194

EDIT: I am uncertain which steps I took to resolve this problem, and am no longer seeing this error message so I cannot test the solutions below. Please try them individually as different answers seem to be working for different people.

The iOS version works fine, but running Android Studio on my Mac I get the following Gradle Build error (paraphrased):

:ReactNative:Running ‘[node, -e, console.log(require(‘react-native/cli’).bin);]’ command failed.

- Where:
Script ‘/Users/…/Desktop/…/node_modules/@react-native-community/cli-platform-android/native_modules.gradle’ line: 154

- What went wrong:
A problem occurred evaluating script.
> Cannot run program “node”: error=2, No such file or directory

Caused by: java.io.IOException: Cannot run program “node”: error=2, No such file or directory

I've tried so many things:

I used to be able to still run yarn android in Terminal, but even that has stopped working.

1

39 Answers 39

468

It's because Android Studio couldn't find node and should be run from a terminal window.

If you are using Mac you can run Android Studio using this command in terminal. Note that if Android Studio is already running, it will need to be shut down completely before running the command.

1. Run this open -a /Applications/Android\ Studio.app

If you installed Android Studio through Jetbrains Toolbox version 1.x, run

open -a ~/Applications/JetBrains\ Toolbox/Android\ Studio.app

If you installed Android Studio through Jetbrains Toolbox version 2.x, run

open "Applications/Android Studio.app"

2. Then sync Gradle

And this will solve the problem.

Note: If you are using Node through nvm, you should run nvm use [version] in the same terminal window before running the above command to open Android Studio.

Sign up to request clarification or add additional context in comments.

17 Comments

Worked for me on Apple Silicon @TimurGaitov for whatever reason Android Studio is not using .zshrc PATH vars so opening it from terminal ensures that it will
I guess, this is a bug in Android Studio Bumblebee 2021.1.1. Same for me on Intel Mac. Related bug report, I found: youtrack.jetbrains.com/issue/TBX-7313
Fixed in Android Studio Bumblebee | 2021.1.1 Patch 1 (February 2022): androidstudio.googleblog.com/2022/02/…
Unfortunately it's not working. I encountered this issue previously and it has been solved. But suddenly got this again. Damn RN!
Ran into this problem in Android Studio Ladybug | 2024.2.1 on macOS 15 and closing Android Studio, then running ./gradlew --stop and finally open -a /Applications/Android\ Studio.app fixed the problem.
|
122

Linking Node.js (installed via NVM) to /usr/local/bin/node

To make Node.js accessible system-wide (e.g., from VS code, Android Studio’s built-in terminal,... ), create a symbolic link:

sudo ln -s "$(which node)" /usr/local/bin/node

You can verify it’s working by running in the Android Studio terminal:

node --version

Note: This step must be repeated whenever you change the Node version using nvm use

Tested Environments:

  • Ubuntu 20.04 with Node.js 14.15.0

  • macOS Sequoia with Android Studio Ladybug

4 Comments

this doesn't resolve the issue for some reason, I'm on macOS catalina, do u have an idea what else I could try ?
This resolved my issue. The reason why this worked is because I used to run Android Studio from terminal which had the .bashrc loaded and thus knew where to find node executable. The problem occurred when I ran Android Studio outside the terminal and my .bashrc did not load. If node is installed using nvm, then it won't have an executable on the PATH, unless you explicitly add it to the PATH. The command above will add a symlink to /usr/local/bin/ which is on the PATH and it will point to the location of node executable.
Worked for me on Ubuntu latest. Android terminal was somehow able to run node, but build command always gave error about node.
You saved my day, thanks. Working like charm on Mac
110

In my case with this setup:

  • Apple chip M1
  • Android Studio arctic fox 2020.3.1 Patch 2

I previously ran the command mentioned above, but I kept getting the same error:

sudo ln -s "$(which node)" /usr/local/bin/node

I had to update the gradle version in the project (android/gradle/wrapper/gradle-wrapper.properties)

from:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

to:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip

and execute this command in the project:

cd android && ./gradlew clean

or just delete this folder instead of the executing the previous command: android/.gradle

And after doing these steps I no longer have any problem.

4 Comments

I am already on Gradle 6.9 and I still have this issue.
Its not working for me in M1 Macbook Pro
You probably have to create /usr/local/bin first by running sudo mkdir /usr/local/bin
"sudo ln -s "$(which node)" /usr/local/bin/node" This command works for me in latest android studio version ladybug in Apple M1 Thanks
62

Solution

Running chmod +x /Applications/Android\ Studio.app/Contents/bin/printenv in the terminal and restarting Android Studio will make the gradle sync work again.

Detail

I am using the latest Android Studio and I did a patch update of the application. My system is running macOS 12.1 on a M1 Pro Apple CPU.

After the restart I could not run my react native application and the gradle sync failed. Any fixes above did not help for me. So I read the gradle log file idea.log in detail. In the very beginning in the log I see the application printenv has some issues.

loading shell env: /bin/zsh -l -i -c '/Applications/Android Studio.app/Contents/bin/printenv' '/var/folders/7y/gz2kx4917yl_804mbfrnkqxc0000gn/T/intellij-shell-env.9046002349811239017.tmp' 
...
.intellij.util.EnvironmentUtil - can't get shell environment 
java.io.IOException: command [/bin/zsh, -l, -i, -c, '/Applications/Android Studio.app/Contents/bin/printenv' '/var/folders/7y/gz2kx4917yl_804mbfrnkqxc0000gn/T/intellij-shell-env.9046002349811239017.tmp']
exit code:126 text:0 out:zsh:1: permission denied: /Applications/Android Studio.app/Contents/bin/printenv

After that I go to folder /Applications/Android Studio.app/Contents/bin/ and list printenv in my terminal and saw that printenv did not have the execute rights:

-rw-r--r--@ 1 user admin 152080 Jan 28 09:12 printenv

Android Studio

Android Studio Bumblebee | 2021.1.1 Build #AI-211.7628.21.2111.8092744, built on January 19, 2022 Runtime version: 11.0.11+0-b60-7772763 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 12.1 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 10 Registry: external.system.auto.import.disabled=true

2 Comments

This was the issue for me also, same setup. Though the command had to be entered as follows to escape the space in the directory: chmod +x /Applications/Android\ Studio.app/Contents/bin/printenv
This fixed the issue for me as well after upgrading to Android Studio Bumblebee. For anyone who installs Android Studio through Jetbrains Toolbox, the fix is the same, just with a different path, i.e. chmod +x ~/Library/Application\ Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8092744/Android\ Studio.app/Contents/bin/printenv
40

For M1 Mac, I downloaded Android Studio (Mac with Apple Chip) version and faced this issue.

It got fixed for me by changing the gradle version to 6.9-rc-1.

This can be done from File -> Project Structure -> Project -> Gradle Version -> Type or select "6.9-rc-1" and click OK button.

You can find similar and more solutions here as well.

Gradle sync failed: Cause: error=2, No such file or directory

Comments

26

Had the same issue in m1 mac and opening the android studio via terminal worked for me
open -a /Applications/Android\ Studio.app

4 Comments

There is already an accepted answer with the same solution. It would be better to keep @Aly's answer as primary choice.
Doesn't work for my m2 Mac.
That worked for me! Maybe Jetbrains' toolbox are not injecting the node path correctly?
It's working for Apple M1 Pro
25

Android Studio uses PATH environment variable that is available when the Android Studio process is started up, and your Node binary directory should be in that PATH.

I got this same error in Linux when I had Node installed via n (Node version management tool) which sets the Node path at Bash startup.

The problem in my case was that I started the Android Studio from the desktop and because the Bash startup file was not executed, also the Node path was not set.

The solution was to run Android Studio from the command line.

You could also try to pass the PATH environment variable directly to Android Studio while starting it from the command line:

PATH=$PATH:/path/to/node/bin/ /path/to/android/studio/bin/studio.sh

3 Comments

Since my node is already in /usr/local/bin/node, the answer from @Mostav doesn't help. However, open Android Studio from terminal as suggested here resolves the issue. I don't have to specify the PATH.
@FanchenBao you can add the path in the file bin/studio.sh then you don't have to run android studio from command line
Running from the command line works. Since the issue was just with finding node (which I installed via brew) I decided instead to modify the top-level build.gradle file. Find the "commandLine" line that executes "node" and hard code the path to wherever you have node installed.
25

I just ran into this issue as well, and for me the solution was to stop the running Gradle daemon:

./gradlew --stop

3 Comments

To the downvoters: This is a complex issue with multiple potential solutions. Even if this did not help in your specific case, it does definitely work in others. There is no reason to downvote.
Thank you! This worked in my case. Problem for me started after updating Android Studio and I assume some gradle task was in progress and update somehow did not stop it properly.
It's working for me too!!! thank you
18

I'm on my Mac, and i solve this by close the android studio completely(close the process), and restart it.

2 Comments

Thanks, seems to happen after MacOS updates for some reason, but a restart fixes.
that fixed it for me. on Mac, you can press command + q to close an app entirely
17

If you are running MacOS + NVM (Node Version Management) + M1, M2, M3 + Homebrew etc. this is what fixed the issue for me.

You need to STOP ALL GRADLE DAEMONS. With command:

./gradlew --stop

Then open Android Studio from your Terminal with this command and NOT THE DOCK

open -a /Applications/Android\ Studio.app

3 Comments

This solved my issue. Thank you!
Thank you for letting me know! This was the first time I've posted a solution, was killing me for days and finally got it to work. Hopefully others will see this reply before they give up hahaha
The solution worked for me on MacOS Sonoma Version 14.5 (23F79). Thanks @ColbyMcHenry for sharing your effort +1.
9

I struggled with this a long time on my M1 mac mini. I was getting this error after opening RN android project in Intellij IDEA during gradle sync and also while trying to run ./gradlew commands from command line.

What seems to be a solution for me:

  • rm -rf .gradle (in the RN_PROJECT/android folder)
  • killall java (to stop running gradle daemon)
  • updated node to v16.8.0

I think the real solution is the first step. Now the project opens in IDEA without errors and I can run ./gradlew commands.

Comments

9

On a Mac with M1, upgrading Android Studio fixed the issue for me. I upgraded from Arctic Fox to Bumblebee.

Also used this version of Gradle (android/gradle/wrapper/gradle-wrapper.properties):

distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip

Comments

9

Nothing helped me, just when I changed Gradle JDk it started working

4 Comments

In my case running one project with "react-native": "0.61.2", worked after install azul-11 - Azul Zulu 11.0.20, just using the gui to install.
This worked for me as well. It was set to use the Android Studio Gradle JDK so I changed it to use JAVA_HOME and it seemed to work. Thanks.
I TRIED EVERYTHING for hours. And this is the only solution that helped. Thank you so much!!!
If you are using Android Studio Narwhal (2025.1.2) or newer, the solution is almost the same, just choose "Use Gradle from" = "Wrapper" & "Gradle JDK" = "zulu-17" (or zulu-11, depend on your RN)
7

Invalidate Caches & Restart on File Tab in Android Studio.

Comments

5

How I solved the same issue.

  1. Open Android studio via terminal
  2. Build Project Like before

Note: I installed node via nvm (I believe that's why I had the issue)

If you installed android studio via snap then its pretty simple to launch it via command line.

Open project folder in terminal and run:

android-studio .

Comments

5

In android Studio, I solved this problem when it happened to me as follows:

1 - Go to File - Invalidate Caches / Restart; 2 - Choose the option "Invalidate and Restart".

Comments

3

I have tried most of the answers posted here but the only solution worked was to upgrading the gradle to 6.9 or later.

File -> Project Structure -> Project -> Gradle Version = 6.9(Select version 6.9 or later from dropdown).

Wait for it to download all modules and it should load your project.

Comments

3

Adding what worked for me on MacOs Monterey.

I updated the graddle version using one of the solutions here. This can be done from File -> Project Structure -> Project -> Gradle Version -> Type or select "6.9-rc-1" and click OK button.

Double-check if node is installed with node --version, if it is open -a /Applications/Android\ Studio.app Open the project and the error should disappear.

1 Comment

Changing the current gradle version worked for me.
2

I was able to make it work in android studio bumblebee by running this command in terminal on mac,

sudo chmod +x /Applications/Android\ Studio.app/Contents/bin/printenv

and then restart the android studio.

Comments

2

you can use: open your project -> run:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

1 Comment

run: open -a /Applications/Android\ Studio.app
1

You can kill gradle daemon, or just restart your machine if you made some changes, and it will work.

Comments

1

Many of these answers are half-right but you must do both of these things:

  1. Make sure that the $PATH variable includes wherever your node is installed. You will will probably set this in .bashrc.

  2. Start Android Studio from the command-line.

Comments

1
  1. close android studio
  2. end any android task from the task manager
  3. use terminal to build the app using
cd android && ./gradlew build
  1. launch android studio
  2. you should be able to run your app on a simulator

Comments

1

Change the default JDK version from Android studio embeded JDK11 to JDK zulu version. That works for me on Apple M2. This changed the gradle scripts running env PATH, after which node can be found. But I don't know why this change affect env.

Comments

1

change the gradle settings to use JAVA_HOME instead of GRADLE_LOCAL_JAVA_HOME or any other gradle jdk

Comments

1
`FAILURE: Build failed with an exception. 
* What went wrong: A problem occurred evaluating project ':react-native-gesture-handler'. 

> A problem occurred starting process 'command 'node'' 
* Try: > Run with --info or --debug option to get more log output. 
> Run with --scan to get full insights. > Get more help at https://help.gradle.org. 
* Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':react-native-gesture-handler'.`

For me this issue came because I installed node js using NVM. I resolved the issue by

  1. Close Android Studio completely
  2. nvm use 22.18.0 # or whatever version you're targeting
  3. open -a /Applications/Android\ Studio.app
  4. Then sync the gradle

Comments

0

I had this issue on M1 mac, found a solution after 3 days, it was because of nvm and .zsh having issues. If you used brew to install it like i did, it's going to cause a lot of issues.

Solution:

I had to uninstall nvm

rm -rf ~/.nvm
rm -rf ~/.npm
rm -rf ~/.bower

Then install nvm via instructions on readme on its github page

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

Other than that, there is a section about troubleshooting M1 macs, that might help futher if needed. But other than that, Android Studio works fine now without having to open it via terminal or any other work-arounds. (You might have to agree to the sdk license agreement if your build fails, view the build tab for the issue, to agree to the license, just go to Tools > Sdk Manager and uninstall the sdk, click apply and retick it and Apply to reinstall it and it will ask you about the license agreement also.

Comments

0

This is not a specific answer to the question, but as some of the comments here helped me resolve my issue, maybe this answer will help someone else.

I was struggling to run a Gradle project using Intellij IDEA on Ubuntu 22.04. It was giving me the same error: Cannot run program "X": error=2, No such file or directory.

Here is what I did to overcome that:

echo 'export PATH=$PATH:/path/to/X' >> ~/.bashrc

echo 'export PATH=$PATH:/path/to/X' >> ~/.profile

sudo echo 'export PATH=$PATH:/path/to/X' >> /etc/environment

I also added the path variable to Intellij IDEA: click File -> Settings -> Path Variables and then add the variable in question (name of the program: X).

As @Jari-Jokinen mentioned above, for the IDE to use program 'X' from /path/to/X you need to restart your computer. Both Intellij IDEA and Android Studio are similar and developed by Jetbrains, so I hope this can be useful to someone.

Comments

0

For me.

I'm using a Mac Pro 2019 with Intel Processor.

when I executed yarn Android I got that same error the author said.

The only thing that really works.

Looks like that, in my case, some Android Studio config was wrong.

Comments

0

There are a lot of solutions about this issue and most are talking about updating the gradle plugin. I have tested a lot of solutions and running the latest Android Studio version (Chipmunk 2021.2.1 Patch 1).

The main issue is still that AndroidStudio, with gradle version lower than 6.9.x, can not lookup properly the PATH environment, which is set by /bin/printenv tool from Android Studio application package itself. If you see in the Android Studio logfile that it can not execute the printenv command, please update to latest Android Studio version.

In 'Project Structure' select 'Gradle Version' 6.9 or higher and you can build your project properly.

In 'Project Structure' select 'Gradle Version' 6.9 or higher

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.