Saturday, August 20, 2016

Installing NodeJs on a Linux Mint OS

I had to run a project in Visual Studio Code on a Linux machine (Mint) that needed NodeJs installed so I tried to follow the steps on the official page.

I realized, after some errors, that I was actually missing some things.

On the official page, the commands for the install are listed like this:

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

Before you can run this (successfully) you also need to install curl: sudo apt-get install curl

Apparently, curl, is a client tool used to get files over different kind of protocols, like http(s) and ftp without too much interaction. The legend goes that it can also support authentication (I'm kidding, it isn't a legend, it's true, check the official page) :).

Another thing that baffled me was the last "-" at the end of the first line. Because of it I thought there was just one command so I copied them both and tried to run them... with no success.

So, first take the first line:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

and when it is done, run the next command:
sudo apt-get install -y nodejs

After this you can check what version was installed with the command node -v. When you install Node you also get npm, which is the package manager for npm, basically where all the goodies come from.

Adding Node to PATH

After the installation is complete it is necessary that we add Node to PATH so that all the packages will be installed in that location. The first thing to do is to create a folder named npm in the home folder.

Open .bashrc file with a text editor. This file is also in the Home folder, but it is hidden. Right-click show hidden files.

Add at the end of the file: export PATH="$HOME/npm/bin/:$PATH".

If the terminal window is open, close it and open it again, then type echo $PATH and you should see the path to npm/bin listed.


No comments:

Post a Comment