To install the latest version of Node.js on Ubuntu, follow a few simple steps. First, youâll need to update your package list. Then, install Node.js from the official repository, which always provides the newest version. Node.js is a popular runtime environment that allows you to run JavaScript code outside a browser. Itâs essential for developing modern web applications.
You can also use the Node Version Manager (NVM) to install a specific version of Node.js on your system.
Step 1: Configuring Node.Js PPA
Node.js has two types of releases: LTS (Long Term Support) and the current release. Choose the version you need for your project. Let’s add the PPA to your system to install Node.js on Ubuntu.
- Use Current Release: During the last update of this tutorial, Node.js 22 is the current Node.js version available.
sudo apt install -y curl
curl -sL https://deb.nodesource.com/setup_
22 .x | sudo -E bash -
sudo apt install -y curl
curl -sL https://deb.nodesource.com/setup_
20 .x | sudo -E bash -
For this tutorial, I am using the latest current release and added their PPA to my system.
Step 2: Install Latest Node.js on Ubuntu
You have successfully configured Node.js PPA in your Ubuntu system. Now execute the below command to install Node on Ubuntu using apt-get. This will also install NPM with node.js. This command also installs many other dependent packages on your system.
sudo apt install -y nodejs
That’s it. This will install Node.js on your Ubuntu system.
Step 3: Check Node.js and NPM Version
After installing node.js verify and check the installed version. You can find more details about the current version on node.js official website.
node -v
v22.9.0
Also, check the npm version
npm -v
8.19.3
Step 4: Create Demo Web Server (Optional)
This is an optional step. Suppose you want to test your node.js install. Let’s create a web server with “Hello World!” text. Create a file server.js
sudo nano server.js
and add the following content
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');
Save the file and close. Then start the Node application using the following command.
node server.js
debugger listening on port 5858
Server running at http://127.0.0.1:3000/
You can also start the application with debugging enabled with the following commands.
node --inspect server.js
Debugger listening on ws://127.0.0.1:9229/938cf97a-a9e6-4672-922d-a22479ce4e29
For help, see: https://nodejs.org/en/docs/inspector
Server running at http://127.0.0.1:3000/
The web server has been started on port 3000. Now access http://127.0.0.1:3000/ URL in browser. Now you will need to configure a front-end server for your app.
Conclusion
In summary, we have learned how to install Node.js on Ubuntu and similar systems using a new official PPA repository. This makes it easy to start developing with Node.js on Linux. We can also use this repository to keep our Node.js installations up-to-date with the latest stable versions. Be sure to check out other tutorials on our website for more tips and tricks about using Node.js!
55 Comments
“It is a server-side framework” – NO IT’S NOT
Thanks
W: GPG error: http://dl.google.com/linux/chrome/deb stable InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 78BD65473CB3BD13
E: The repository ‘http://dl.google.com/linux/chrome/deb stable InRelease’ is not signed.
N: Updating from such a repository can’t be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
I’m getting these error while adding nodejs ppa
Removed broken chrome PPA or try below tutorial to fix error:
https://tecadmin.net/expired-key-expkeysig-with-apt/
Illegal instruction] – rollbackFailedOptional: verb npm-session xxxxxxxxxxxxxxxxx
top question: how to exit vim?)
Press escape (Esc) to open command mode in vim and then type:wq and press enter.
Thanks! Its so helpful
Thank you very very much! I was lost…
Very helpful! Thank you!
dev50@dev50-HP-15-Notebook-PC:~$ node –inspect server.js
Debugger listening on ws://127.0.0.1:9229/fd423a7e-c779-44d0-ac4f-312873eb4482
For help, see: https://nodejs.org/en/docs/inspector
Server running at http://127.0.0.1:3000/
events.js:186
throw er; // Unhandled ‘error’ event
^
Error: listen EADDRINUSE: address already in use 127.0.0.1:3000
It looks some other application is already running on port 3000. To find out process run below command:
netstat -tulpn | grep 3000
Thanks for this tutorial all works correctly for me.
I used Ubuntu 18
muchas gracias, funciona bien ! saludos from venezuela
Thanks worked perfectly on ubuntu 14
only download the v8, not the lts
E: coult not get lock /var /lib/dpkg/lock-fronted -open
this error shows when i enters te command
http://archive.ubuntu.com/ubuntu yakkety InRelease
Could not connect to 125.200.13.2:80 (125.200.13.2). – connect (111: Connection refused)
this is the error i’m getting while installing ppa
even sudo apt-get update is also throwing the same error
What can i do please do reply
On certain servers, port 3000 too needs to be opened by using the ufw command
Thank you for the post.
Thanks! worked perfectly
Thanks …show de Bola @@@.
Thank you man….
Thanks man, I always use this code to install nodejs. Thanks again..
On Ubuntu 18.04 server, I had to use ‘software-properties-common’ instead of ‘python-software-properties’:
virtualbox-iso: Package python-software-properties is not available, but is referred to by another package.
virtualbox-iso: This may mean that the package is missing, has been obsoleted, or
virtualbox-iso: is only available from another source
virtualbox-iso: However the following packages replace it:
virtualbox-iso: software-properties-common
virtualbox-iso:
virtualbox-iso: E: Package ‘python-software-properties’ has no installation candidate
it’s correct!. You need to use âsoftware-properties-commonâ instead of âpython-software-propertiesâ.
Hello, Thanks for the info.
Whenever I run curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -, or any version, I get this response – “bash: curl: command not found.” What seems to be the problem?
Run below commands first:
sudo apt-get install curl
It was installed. Thank you so much!
node -v tells me node is not installed. Installing node-legacy puts down a symlink so that node -v works.
However it returns v4.7.2.
Ubuntu 17.04.
Turns out my apt sources.list had a site which couldn’t be reached, so the PPA wasn’t being added, so it was just installing the distro version. With that fixed nodejs -v returns v8.9.1. nodejs-legacy won’t install though. I’ll just make the symlink myself.
Thanks Jeff! You help me very much!
thanks
hi how remo this??
How set for custom domain on ubuntu ?
var http = require(‘http’);
http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/plain’});
res.end(‘Hello World\n’);
}).listen(80, “customdomain.com”);
console.log(‘Server running at http://customdomain.com:80/‘);
Hi Din,
You need to setup Nginx or Apache as a reverse proxy server in front of Nodejs.
https://tecadmin.net/setup-nginx-as-frontend-server-for-nodejs/
Thanks
I have tried installing nodejs 8 , but my system always installs 4.2.6 version.Am using ubuntu 16.04.
How can i solve this?Thanks
Make sure that Curl is installed on your system, pull the repo, it should usually update your repos automatically, then you can run ‘sudo apt-get install nodejs’ to get the latest version
hi
I have same problem and can’t resolve that.if you can please help me.
How can I stop the server? Thanks in advance!
Small error in code “}).listen(3001, “127.0.0.1”);” listen port should be 3000.
Thank you very much. Article updated.
node -v _does not display the version_, it prompts you to install nodelegacy.
To view the node_js_ version, you run _nodejs -v_
sudo apt-get install nodejs *does not install npm, you need to install it manually*
Which OS and version are you using?
Did you do sudo before running this command? The previous command uses sudo which is carried forward here too. If you took a long time to run the second command, the sudo will need to be revoked again.
Simply follow the entire tutorial again but a bit faster this time.
Thank you. Your article was helpful.
Great article, quite helpful
Thanks for sharing.. learning lot of things
Small typo in the node.js code:
res.end(‘Hello Worldn’);
Should be:
res.end(‘Hello World\n’);
just a simple fix by adding the forward slash.
Thanks Brandon,
Tutorial has been updated.
The last command is wrong : it should be
nodejs –debug http_server.js
for version : nodejs -v
Thanks that worked for me.
Thank you!!
Thanks admin… works perfectly on Ubuntu 16.04
Thanks work great for me thank you !