Setting up Node Server on Linux
You can install a Node server on Ubuntu using two methods.
- Ubuntu Official Repository to install node.js
- NodeSource Repository to install the latest version of Node.js
Install the Node server: Ubuntu Official Repository
Node.js is available in Ubuntu's Official repository and can be installed with only a few keystrokes. To install Node.js on your Ubuntu operating system, follow the steps below.
Open your terminal (Ctrl + Alt + T) and run the following commands -
|sudo apt install nodejs|
Enter your password and hit Enter.
Verify the installation using the following command -
|node -v // You can also use this command: node -version.|
You should see an output mentioning the Node.js version.
Important: Now, you have installed the Node server in your Ubuntu system. However, it is highly recommended to install NPM (Node Package Manager) alongside Node.js.
You can install npm using the following command -
|sudo apt install npm|
Verify the installation -
You have successfully installed the Node server and NPM in your ubuntu system.
Install the Node server: NodeSource Repository
The NodeSource repository contains the most recent version of Node.js. To install Node.js on Ubuntu using NodeSource Repository, follow the steps below.
Open your terminal or press Ctrl + Alt + T and use the following commands to update and upgrade the package manager:
|sudo apt-get update|
sudo apt-get upgrade
Install the python dependencies.
|sudo apt-get install software-properties-common|
Add Node.js archives to your system. These archives will be extracted to install the Node server.
|# Installing Node.js v17.x.|
curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
# to install previous versions of Node.js, say v16.x, replace setup_17.x with setup_16.x
Use the command given below to install both the Node Server and npm in your Ubuntu system.
|sudo apt-get install -y nodejs|
Verify the Node server installation -
Verify the npm installation -
You have now successfully installed node server and npm on your system.
Frequently asked Questions
Q1. Does node js work on Linux?
Q2. How do I run a node program?
Ans: To launch a Node.js program, use the node globally accessible command (once you've installed Node.js) and specify the file's name you wish to run. Make sure you're in the same directory as the app before performing the command.
Q3. How do node js servers work?
Q4. Is node js a server side language?
In this blog, we learned how to install Node Server and NPM on a Linux machine. NPM is the package manager for Node Server. It is used to install and manage various node modules, which are crucial for handling server-side dependencies.