Install Node.js on Linux VPS Quickly and Easily

Learn how to install Node.js on a Linux VPS using easy commands with package managers like yum and apt. Verify your installation and start running JavaScript applications server-side.

🤖AI Overview:

Installing Node.js on a Linux VPS involves setting up the JavaScript runtime environment using common Linux package managers such as yum and apt. This process includes adding the NodeSource repository, installing Node.js and NPM, and verifying versions to ensure a successful setup. The method supports popular Linux distributions like CentOS, Ubuntu, and Debian.

Which operating system is more suitable?

For sure: Centos; You may ask about Why CentOS 7? This is why: CentOS is easier to use and more secure; CentOS 7 is also one of the new and supported versions, which is more popular than other versions.

As you may know, CentOS 8 is released, but there are some problems with the installation process. At the moment, CentOS 7 is the most reliable and most compatible operating system to install Node.JS and Npm on Linux VPS.

Can Linux OS be a good choice for Node.js and NPM?

Somehow; If you want to have less trouble with NodeJS and its packages, use Linux…

It depends on your choice and your needs, we can compare the differences with the experience of developers: using node.js and NPM in Windows VPS versus Installing node.js using terminal

And using on Linux VPS will definitely have more problems.

About Node.JS and NPM…

First; NPM is, in simple terms, a large, OpenSource library that is a kind of Package Manager; NPM stands for Node Package Manager and is commonly used as Node.JS package management software; Node.JS’s main place is in the backend, in order to manage node.js packages well, a package manager called npm is provided.

Node.JS and NPM prerequisites

If you want to be able to access Node.JS and npm, you will need the following prerequisites:

1. Putty installation

2. Add the NodeSource yum command

By installing Putty and accessing it, you will be able to log in to the server to install the desired services on your desired server; To learn how to log in to a Linux server, you can also read the article in OperaVPS entitled: Connecting to a Linux VPS!

Note: The following prerequisites are only recommended for CentOS distribution on a Linux server.

  • To add NodeSource yum prerequisites, enter the following Curl command on your server:
curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -

After entering the command, you will see the content as shown below; Wait about twenty seconds:

install Node.js

Finally, the output of the command will be similar to the following image:

install Node.js

Install node.js and npm on CentOS 8

You will be able to install the Node.js and NPM services using the following command:

yum install nodejs

word image 2

How to check Nodejs Version On CentOS 8?

You can check the installed version of Node.JS using the following command:

Node.JS

node --version

word image 3

The output of the command will be the same as the inserted image;

You can also check the installed version of NPM using the following command:

NPM

npm --version

word image 4

The output of the command will be the same as the inserted image.

Install node.js and npm on Ubuntu 20, Debian 10

Log in to the server and then run the following command on the server and wait for the installation process to complete:

apt install nodejs npm

word image 5

Note: Note that, you can download and install new versions of Node.js and NPM using the given commands!

How To Check Nodejs Version On Ubuntu 20, Debian 10?

You can check the installed version of Node.JS using the following command:

Node.JS

nodejs --version

word image 6

The output of the command will be the same as the inserted image;

You can check the installed version of NPM using the following command:

NPM

npm --version

word image 7

The output of the command will be the same as the inserted image.

Keep in mind you can also use other ways to install NPM and Node.JS:

  • Install Using API

Log in to your virtual server via SSH as a root user and make sure it is updated/upgraded Using the below command:

apt-get update && apt-get upgrade

With the following command, you can easily install Node.js through Ubuntu default repositories

apt-get install nodejs

You also need to install NPM to easily manage Node.js packages

apt-get install npm

Check the installed Node.js and NPM version

nodejs -v

V4.2.7

npm -v

3.5.2

  • Install Using PPA

If you need a new version of Node.js, you can install it from the available repositories in the official Ubuntu PPA; Here we want to download Node.js using curl directly, If the curl is not installed, then install it first:

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

Note: This will add PPA and package upgrades.

To install Node.js, run the following command:

apt-get install nodejs

Install the necessary packages(build-essential package)

apt-get install build-essential

Finally, See the installed Node.js version

nodejs -v

v8.9.6

  • Install Using NVM

You can also install Node.js with the help of NVM (Node.js version manager). With this tool, you can install multiple versions of Node.js on Ubuntu.

  • Install some dependencies and library
apt-get install build-essential libssl-dev
  • Download the NVM installation version using the following command
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install.sh
  • Now run the installation file with bash
bash install.sh
  • In this case, anything inside the .nvm directory will be installed in the Home directory too. To apply the changes in .profile file, make it the source
source ~/.profile

Now you can run the following command and check all available Node.js versions:

nvm ls-remote

v8.9.0 (LTS: Carbon)

v8.9.1 (LTS: Carbon)

v8.9.2 (LTS: Carbon)

v8.9.3 (LTS: Carbon)

v8.9.4 (Latest LTS: Carbon)

v9.0.0

v9.1.0

v9.2.0

v9.2.1

v9.3.0

v9.4.0

v9.5.0

  • To install a specific version of Node.js, you can use the following command and add the desired version to the end
nvm install v9.3.0

How to Uninstall Node.js and npm completely

  1. Debian 10, Ubuntu 20
sudo apt-get purge --auto-remove nodejs
  1. CentOS 8
tar -xzvf node-0.10.46.tar.gz
cd node-0.10.46
sudo make uninstall

Common uses of Node.JS

  1. Build one-page applications (SPA)
  2. Build RTA programs
  3. Build a chat room
  4. Build online games under a web browser

Common uses of NPM

  1. Connect with programmers who are working on a similar project like you.
  2. Easy update of used packages if a new version of them is provided
  3. Share your code with other developers
  4. Add different packages to the project to edit them

What packages can be found in NPM?

According to the definitions of survivejs and npmjs; we can say: A minimal npm package should contain metadata in a package.json file and an associated source file (usually index.js). In practice, packages contain more than that and you will have at least a license file and the source in various formats.

Often projects contain more files than are required to execute them; A package is a file or directory that is described by a package.json file; A package must contain a package.json file in order to be published to the npm registry.

Packages can be unscoped or scoped to a user or organization, and scoped packages can be private or public!

Conclusion

Installing Node.js is the foundational step for anyone interested in modern JavaScript development. With various installation options from official installers to package managers and version managers like nvm, you can choose the method best suited to your needs and operating system. Following the clear instructions above will ensure you install Node.js smoothly and correctly, enabling you to begin developing powerful and efficient JavaScript applications.

Remember to verify your installation after setup and consider best practices like using nvm for version management when appropriate. Now that you know how to install Node.js, you are ready to explore its rich ecosystem and develop your projects effectively.

FAQ

Popular choices include Ubuntu 22.04 LTS, Debian 12, AlmaLinux, and Rocky Linux due to their stability and compatibility.

Use "curl" to fetch the setup script for the current Node.js LTS version and execute it with sudo rights.

Run the commands" node --version" and "npm --version" to see their installed versions.

Yes, use NVM (Node Version Manager) to install and switch between different Node.js versions easily.

In most modern installations, NPM is bundled and installed automatically with Node.js.

Use "sudo apt remove nodejs npm" on Ubuntu/Debian or "sudo yum remove nodejs" on CentOS-based systems to uninstall.

These tools are necessary to compile native add-ons required by some Node.js packages.

Regularly update the NodeSource repository scripts or use NVM to manage upgrades.

Run Node.js applications with the least privileges, keep software updated, and monitor dependencies for vulnerabilities.

Leave a Reply

Your email address will not be published. Required fields are marked.