Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm is installed using nvm but IntelliJ does not know about it

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?

like image 651
Raymond Pang Avatar asked Oct 25 '16 16:10

Raymond Pang


People also ask

How do I know if npm is installed successfully?

To see if NPM is installed, type npm -v in Terminal. This should print the version number so you'll see something like this 1.4. 28. Create a test file and run it.

Does NVM also install npm?

nvm doesn't handle npm. So if you want to install Node. js 0.4. x (which many packages still depend on) and use NPM, you can still use npm 1.0.

Is NVM and npm same?

NVM is a node. js version manager. It provides easy installation, switching between versions and retains globally installed packages for each version. NPM is a package manager, which help you install libraries, plugins, frameworks and applications.


2 Answers

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)

like image 118
Raymond Pang Avatar answered Sep 20 '22 07:09

Raymond Pang


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>

like image 41
Tim Avatar answered Sep 20 '22 07:09

Tim