32

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
  • 667
  • 1
  • 7
  • 17

15 Answers15

19
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) Edit Configurations

Tudor
  • 1,510
  • 1
  • 18
  • 17
  • 2
    simple and works, thankyou brother. good job! – Alauddin Afif Cassandra Mar 28 '21 at 17:18
  • 1
    Thankyou I have been struggling with this issue for weeks – Simon Apr 28 '21 at 02:32
  • Running `which node` results `/usr/local/bin/node`. So that would build a symlink to itself, if I get it right. So the problem remains. – Dirk Schumacher May 17 '22 at 05:18
  • @DirkSchumacher uninstall node and install it back using FNM https://github.com/Schniz/fnm – Tudor May 17 '22 at 06:27
  • I've been struggling with this for over an hour. You're a life saver! – Rajat Jun 02 '22 at 16:01
  • Does not work if you then switch node versions. – kamcknig Jun 08 '22 at 16:08
  • @kamcknig then point it to current version used by fnm/nvm – Tudor Jun 08 '22 at 18:49
  • @Tudor, I understand that would need to be done, thanks. just wanted people to know. I myself had misunderstood and thought this was meant to automatically handle the case if you switch node versions with nvm and didn't realize I'd still have to manually update a link. In this case it's simply easier to add the .nvm/versions/ to the list in webstorm. Though I suppose that would clutter up the IDE with a lot of versions and someone might not like that. – kamcknig Jun 09 '22 at 19:26
16

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)

Raymond Pang
  • 667
  • 1
  • 7
  • 17
9

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>

Dario Seidl
  • 4,140
  • 1
  • 39
  • 55
Tim
  • 833
  • 11
  • 11
8

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.

Jörn Brett
  • 91
  • 1
  • 1
6

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
cfnz
  • 196
  • 3
  • 14
5

For me the solution was to move the following lines from ~/.bashrc to ~/.profile and reboot/relogin.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nidomiro
  • 820
  • 2
  • 10
  • 24
3

does it help if you run IntelliJ as admin? On Windows this solves many of the issues I had with setting up Node, Bower and Git

westworld.be
  • 244
  • 3
  • 7
  • Unfortunately, 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 Nov 03 '16 at 15:58
2

I'm using webstorm on mac and had to add path variable to ~/.zshenv (which is the zsh version of ~/.bash_profile):

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
chuckieDub
  • 1,767
  • 9
  • 27
  • 46
1

I had the same issue in mac OS catalina, fixed it by updating Shell path to /bin/zsh in Preferences -> Tools -> Terminal -> Application Settings.

1

As Elena Pogorelova pointed out on the Jetbrains forums the reason why the IDE cannot find the Node script when using NVM is that:

When being launched from desktop/System menu, IDE only sees environment variables configured in ~/.profile (login shell), but not in interactive shell configuration files (like ~/.bashhrc).

So, what I found the best solution is moving the NVM initialization instructions from the ~/.bashrc file to the ~/.profile and reboot after that. In my case was:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
pakobill
  • 416
  • 4
  • 11
0

The issue is that your environment(s) is(are) different from running intellij and which bash session you ran nvm <command (install/use)>. It is usually a good idea to add that line nvm recommends to add into your ~/.bashrc that will export the needed environment variables into each of your bash sessions. If you can run node --version from bash and it prints v6.8.0, your environment is correct, you just need to run intellij from that context, personally I'm not a fan of IDEs so I wouldn't know exactly, but I imagine intellij has a way to be executed from the command line.

Christian Grabowski
  • 2,782
  • 3
  • 32
  • 57
  • If 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 – Raymond Pang Nov 03 '16 at 16:30
  • 1
    @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. – Christian Grabowski Nov 03 '16 at 18:13
  • 2
    @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 http://linuxcourse.rutgers.edu/rute/node12.html section 9.9 for details –  Nov 03 '16 at 18:22
  • @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. – Raymond Pang Nov 05 '16 at 13:48
0

I had the same issue, and fixed it by pointing to /usr/local/bin/bash instead of /bin/bash

Wildhammer
  • 2,017
  • 1
  • 27
  • 33
0

On Windows this works for me... enter image description here

HeyMan
  • 1,529
  • 18
  • 32
0

In my case the PATH was different and didn't contain the path to the nvm folder. I just had to run nvm use inside Intellij terminal:

nvm use <any installed node version>

After that, Intellij PATH was updated with nvm folder path and node and npm commands worked normally.

Hope this helps.

Lano
  • 593
  • 1
  • 7
  • 13
0

After trying most of the solutions presented here, the solution from Igor Kalinovskiy eventually fixed it for me on Mac:

Add export NVM_SYMLINK_CURRENT=true to your .bashrc before NVM-stuff. Then do nvm use default - symlink is created. Then add $HOME/.nvm/current/bin to your PATH in .profile

Original answer: https://intellij-support.jetbrains.com/hc/en-us/community/posts/205964744/comments/360000199399

Instead of nvm use default, you might want to use another version in the IntelliJ shell, e.g., nvm use stable or nvm use 16.

rlayer
  • 1
  • 1
  • 1