Installing Node.js is a crucial step for developers looking to leverage its powerful features and vast ecosystem. In this comprehensive guide, we will walk you through the process of installing Node.js using APT (Advanced Package Tool) and NodeSource. By following these straightforward instructions, you'll be equipped with the latest (LTS or current) version of Node.js, supporting a great development experience and access to a wide range of Node.js libraries and frameworks.
First, install curl.
sudo apt update sudo apt install -y curl
Install Node.js via NodeSource.
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -y nodejs
The above command will install Node.js version 18.x, which was the latest LTS release as of this writing. If a new release is available, or you want to use another version, simply change
18 to the major version number you wish to install.
root user shell.
Make sure Node.js is installed correctly by getting its version number.
It should display something like:
The exact version number might vary depending on which version you installed and/or when you are reading this guide.
After following the steps above, minor and patch upgrades to the version of Node.js you installed can be managed via APT. You can update sources like so:
sudo apt update
With that done, your operating system is now aware of any updates to Node.js. You can upgrade your system like so:
sudo apt upgrade
This will upgrade all packages on your system, including Node.js.
You are now ready to run and serve Node.js apps. You may choose to write and/or run completely custom Node.js apps, or you may choose to go with a framework like Next.js.