npm is installed using nvm but IntelliJ does not know about it
Solution 1
It is because idea terminal launches a login shell by default, so the .bashrc file is not read.
To solve the problem:
Open "Settings" in IntelliJ. Then, expand "Tools" in the left panel, then click 'Terminal'.
Add -i to the Shell Path. (eg. /bin/bash -i)
Solution 2
This fixed it for me:
NVM patches environment variables on terminal startup only. If the IDE is launched from Terminal, it inherits Terminal environment (including modified PATH environment variable, added NVM_DIR env var, etc). In that case, there are normally no problems with using node/npm, because Idea sees the correct PATH value. For bash as shell, workaround could be the the following: edit your Idea launcher and set command to "/bin/bash -l -c "/path/to/idea.sh". This command will perform bash login (i.e. reading your .bashrc/.bash_profile files) and after that will run idea
https://intellij-support.jetbrains.com/hc/en-us/community/posts/205964744/comments/205060164
Just edit your Intellij launcher / startup script and change that to /bin/bash -i -c <path to idea.sh>
Solution 3
ln -s "$(which node)" /usr/local/bin/node
The command will create a symlink from the current node version you have installed. If there is already a /usr/local/bin/node file, delete that since it might be a broken link.
Also change in Edit Configuration from whatever project version you have to "node" (which will be the link created with the above command)
Solution 4
I am running on Ubuntu and had the same issue shown by not being able to run node from the IntelliJ Idea terminal or being able to run gradle tasks that start a nvm related process.
Some of the existing answers fixed it for me when using the terminal within Idea, but running the gradle tasks still did not work. Starting it with bash -l -c... as found elsewhere did not work either.
Initially solved it by creating a start script that does the same as what nvm does, and then did the bash -l -c... and that worked, but found (after that) that the -i as stated above works as well and is simpler... So my .desktop exec entry line is now:
Exec=/bin/bash -i -c /opt/intellij/idea-IU/bin/idea.sh "%f"
Just mentioning it here as the accepted solution does not work for starting nvm related gradle tasks from within Idea.
Solution 5
Adding the nvm node interpreter worked for me:
Settings -> Languages & Frameworks -> Node.js and NPM -> Node interpreter
Chose ~/.nvm/current/bin/node
. If it doesn't show up in the interpreter selection, click ...
and add it as a new path.
Related videos on Youtube
Raymond Pang
Updated on June 04, 2022Comments
-
Raymond Pang almost 2 years
I installed NPM using NVM.
When I use npm in Intellij terminal, it says I don't have NPM installed. But if I use Ubuntu terminal, it is working.
Here are what I tried:
I have already tried to set my node interpreter (in "Language and Framework" > "Node and NPM", set to
~/.nvm/versions/node/v6.8.0/bin/node
).I have also already enabled the Node.js Core library. There it shows the npm package is included.
But the IntelliJ terminal still complains I haven't installed npm. Why?
-
Raymond Pang over 7 yearsUnfortunately, it is not working. I did gksudo -k -u root "/opt/idea-IU-162.2032.8/bin/idea.sh" %f to run IntellIjJ as root, and I tried node --version inside, and it still doesn't show anything. Thanks for your help anyway.
-
Raymond Pang over 7 yearsIf you mean this line of code, export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" , it is already added and I did source ~/.bashrc but the one it outputs is v4.2.6 from /usr/bin/node --version, instead of the v6.8.0 one installed with nvm, that means it doesn't solve the problem
-
Christian Grabowski over 7 years@RaymondPang ok good, then you probably just need to run intellij from the command line, so that those environment variables are within intellij's environment.
-
Admin over 7 years@RaymondPang Christian is right, your issue is that NVM's env vars aren't being passed to intellij due to is not being a child process of bash. See linuxcourse.rutgers.edu/rute/node12.html section 9.9 for details
-
Raymond Pang over 7 years@Christian Grabowski I typed /opt/idea-IU-162.2032.8/bin/idea.sh in Terminal to launch intelliJ, Is this exactly what you mean by "running from the command line"? After that, I still cannot get the same environment variable and Node in intelliJ.
-
lealceldeiro about 4 yearsDoes this work with newer versions of IntelliJ IDEA?
-
jsh6303 about 4 yearsHow do we find the path to
ide.sh
? -
Geoff Davids over 3 yearsCheck the properties of your launcher shortcut. You'll find the launcher in
/usr/share/applications
(for global install) or~/.local/share/applications
(for local install) -
Alauddin Afif Cassandra about 3 yearssimple and works, thankyou brother. good job!
-
Simon almost 3 yearsThankyou I have been struggling with this issue for weeks
-
Abdelsalam Shahlol over 2 yearsWorked on phpstorm 2020.1 and Kubuntu. Thanks @Tim
-
Janith Ganewatta over 2 yearsAfter adding this, I had to close and reopen the IntelliJ for this to work. I am using the latest IntelliJ.
-
Andi-lo over 2 yearsThis also solved it for me using zsh: /bin/zsh -i
-
Vlad R about 2 yearsworked like a charm, thanks man!