Node.js is a powerful JavaScript runtime built on Chrome's V8 engine, widely used for building scalable network applications. This article will walk you through the steps of installing Node.js 22 LTS on an Ubuntu-based system, ensuring that you have the necessary tools to start developing with Node.js.
Prerequisites
Before you begin the installation, ensure you have:
- An Ubuntu-based system (version 20.04 or later recommended)
- Sudo privileges for installing packages
Installation Steps
Step 1: Update System Packages
It's essential to start by updating your system packages to ensure all software is up-to-date. Open your terminal and run the following command:
sudo apt update
Step 2: Install Curl
Now before you begin, make sure that curl is installed on your machine. Curl is necessary for downloading the Node.js setup script. If it's not installed, you can install it using this command:
sudo apt install -y curl
Step 3: Download Node.js Setup Script
Next, download the Node.js LTS setup script from Nodesource. This script configures the necessary repository for Node.js installation.
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
Step 4: Run the Node.js Setup Script
Execute the downloaded setup script to configure the repository:
sudo -E bash nodesource_setup.sh
Step 5: Install Node.js
Now, install Node.js using the apt package manager:
sudo apt install -y nodejs
Step 6: Verify Node.js Installation
Finally, confirm that Node.js is installed correctly by checking its version:
node -v
You should see the Node.js version number printed in the terminal, indicating a successful installation.
Troubleshooting Tips
- If you encounter issues with downloading the setup script, ensure that your internet connection is stable.
- For permission-related errors, double-check that you have sudo privileges.
- If Node.js installation fails, try running sudo apt update again and repeat the steps.
Final Thoughts
Setting up Node.js LTS on Ubuntu is straightforward with the steps outlined above. By following the steps in this article, you now have a robust environment for developing and running Node.js applications.
Last updated on December 17, 2024