Install nodejs and npm on linux

I had a problem installing nodejs and npm on my Linux server (which is the raspbian pi server). I had everything configured and working with

sudo apt-get install nodejs npm 

Everything was perfect and dandy, until I found out that, apparently, these versions have become old. So I deleted them

 sudo apt-get purge nodejs npm 

Then I found the following answer ( here ) on SO and ran

 curl -sL https://deb.nodesource.com/setup | sudo bash - sudo apt-get install -y nodejs 

Running node -v has version 0.6.19 ... which I suppose translates to version 6.19 as opposed to version 0. However, running npm -v told me that it was not installed. So I cleaned up nodejs again and was looking for another solution. At this point, I decided to follow the material on the nodejs website ( here ). And I executed the following commands.

 curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs 

and

 sudo apt-get install -y build-essential 

2 questions:

1) The installed version is still 0.6.19. I would prefer to have version 4.x, as this is what I am running on my dev machine (macOS Sierra).

2) I still do not have npm. What makes nodejs unnecessary

Any help on any (but preferably 2) would be great. Thanks in advance.

+6
source share
1 answer

I really recommend installing node and npm using nvm . This is the fastest, cleanest and easiest way to do this.

Thus, you install NVM simply:

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

To verify that nvm is installed correctly, close and reopen the terminal and enter nvm. If you get an nvm: command not found message, your OS may not have the required .bash_profile file. In the terminal, enter touch ~ / .bash_profile and run the above script installation again.

Now you can set the node input:

 nvm install <version> 

for instance

 nvm install 4.2.1 

if you just want to install the latest version of node, you can simply type

 nvm install node 

In order to access node and npm as sudo (in order to have <1024 ports), you must run

 n=$(which node) n=${n%/bin/node} chmod -R 755 $n/bin/* sudo cp -r $n/{bin,lib,share} /usr/local 
+12
source

All Articles