The following steps would help to install nodejs on a development machine.
To install nodejs directly on the Ubuntu using the debian packages
sudo apt-get update
sudo apt-get install nodejs
To uninstall or remove nodejs in Ubuntu
dpkg purge nodejs
dpkg -l nod*
sudo apt-get purge nodejs
sudo apt-get purge –auto-remove nodejs
sudo apt-get purge nodejs
sudo apt-get autoremove
Though it is a quick way to install nodejs using package on Ubuntu, but not the preferred one, to have a more controlled installation where in multiple versions of nodejs can co-exist, it is better to install in the opt directory using the tar files.
Two approaches which can be thought off during deployment
app: nodejs application and runtime would be there on one server, and the end users would be using this server IP address to access the nodejs application
web:NGINX web server which would serve as front end for end users to make requests. This server would act as a reverse proxy to the nodejs application. End users would access this NGINX IP Address to access the nodejs application
If only one server is preferred, for the remaining part of the tutorial just replace the IP Address with localhost/127.0.0.1
A simple deployment illustration of nodejs where in the web server could be a NGINX web server which would serve as front end for end users to make requests. This server would act as a reverse proxy to the nodejs application. End users would access this NGINX IP Address to access the nodejs application.
Download the latest nodejs from for Linux
user@LT-201:~/Downloads$ wget https://nodejs.org/dist/v6.10.0/node-v6.10.0-linux-x64.tar.xz
–2017-03-05 13:59:50– https://nodejs.org/dist/v6.10.0/node-v6.10.0-linux-x64.tar.xz
Resolving nodejs.org (nodejs.org)… 220.127.116.11, 18.104.22.168, 2400:cb00:2048:1::6814:162e, …
Connecting to nodejs.org (nodejs.org)|22.214.171.124|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 9376372 (8.9M) [application/x-xz]
Saving to: ‘node-v6.10.0-linux-x64.tar.xz’
node-v6.10.0-linux- 100%[===================>] 8.94M 3.84MB/s in 2.3s
2017-03-05 13:59:54 (3.84 MB/s) – ‘node-v6.10.0-linux-x64.tar.xz’ saved [9376372/9376372]
Create a directory to hold contents of the extracted archiv
user@LT-201:~/Downloads$ mkdir node
user@LT-201:~/Downloads$ tar xvf node-v*.tar.?z –strip-components=1 -C ./node //-C option is to Change Directory before performing any operation. –strip-components=1, specifies the number to strip components from files names on extraction.
Next, we’ll configure the global
npm will create symbolic links to installed Node packages, to somewhere that it’s in your default path. We’ll set it to
/usr/local with this command:
user@LT-201:~/Downloads$ mkdir node/etc //this creates a directory by name etc under node directory
user@LT-201:~/Downloads$ echo ‘prefix=/usr/local’ > node/etc/npmrc //this creates a a global prefix for npm, a file with name npmrc with global config
With all nodejs extracted, now we can move the nodejs and npm binaries to our installation location /opt/node with the following command
user@LT-201:~/Downloads$ sudo mv node /opt/
Make root as the owner of the files
user@LT-201:/opt$ sudo chown -R root: /opt/node
Then we move to create symbolic links of the node and npm binaries in the default path. We will put the links in /usr/local/bin with these commands
user@LT-201:/opt$ sudo ln -s /opt/node/bin/node /usr/local/bin/node
user@LT-201:/opt$ sudo ln -s /opt/node/bin/npm /usr/local/bin/npm
Verify the node is installed by checking
user@LT-201:/opt$ node -v
The Node.js runtime is now installed, and ready to run an application! Let’s write a Node.js application.
Refer the next article in the series to create your first application