Question: I have having a bit of an issue with installing nodejs and npm on my linux server (which is a pi running raspbian). I had everything set up and running using 

```
sudo apt-get install nodejs npm

```

All was fine and dandy, until I found out that apparently these versions are now old. So I removed them

```
sudo apt-get purge nodejs npm

```

Then I found the following answer ([here](https://stackoverflow.com/questions/12913141/message-failed-to-fetch-from-registry-while-trying-to-install-any-module)) on SO and ran 

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

```

Running node -v have me version 0.6.19...which I'm assuming translates to version 6.19 as opposed to version 0. However, running npm -v told me that it was not installed. So I once again purged nodejs, and looked for another solution. At which point I decided to follow the stuff on nodejs's site ([here](https://nodejs.org/en/download/package-manager/)). And I ran 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 issues:

1) The version installed was still 0.6.19. I would rather have version 4.x, since that's what I'm running on my dev machine (macOS Sierra). 

2) I still don't have npm. Which renders nodejs useless

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

Answer: 
I really recommend you install node and npm using [nvm](https://github.com/creationix/nvm). This is the fastest, cleanest and easiest way to do it.

That way, you install NVM simply doing:

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

```

To test that nvm was properly installed, close and re-open Terminal and enter nvm. If you get a nvm: command not found message, your OS may not have the necessary .bash\_profile file. In Terminal, enter touch ~/.bash\_profile and run the above install script again.

And you are now able to install node typing:

```
nvm install <version>

```

For example

```
nvm install 4.2.1

```

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

```
nvm install node

```

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

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

```
Sometimes, installing a specific version of the node.js from the authorized source does not work properly. It will be better if will be installed after downloading the node package from the link(<https://nodejs.org/en/>) and following the steps....

1. Unzip the compressed package using the following command:

> 
> `tar --xf node-v16.13.1-linux-x64.tar.xz`
> 
> 
> 

2. Make a directory inside `/usr/local/`:

> 
> `sudo mkdir -p /usr/local/nodejs`
> 
> 
> 

3. Move all unzip files to newly made dir:

> 
> `sudo mv node-v16.13.1-linux-x64/* /usr/local/nodejs/`
> 4. Open `.bashrc` file using command prompt:
> 
> 
> 

> 
> `sudo nano ~/.bashrc`
> 
> 
> 

5. Add the following command inside the `.bashrc` file at the end and
close the file:

> 
> `export PATH=$PATH:/usr/local/nodejs/bin`
> 
> 
> 

6. Print the path for justification:

> 
> `echo $PATH`
> 
> 
> 

7. Verify the node version:

> 
> `node --version`
> 
> 
>