Introduction:
Node.js is a popular runtime environment that allows you to run JavaScript on the server-side. If you’re using Rocky Linux 9 and want to harness the power of Node.js for your web development projects, this step-by-step guide will walk you through the installation process.
Step 1: Update System Packages:
Before installing any new software, it’s important to ensure that your system packages are up to date. Open a terminal on your Rocky Linux 9 server and execute the following command:
sudo dnf update
This command will update your system packages to their latest versions.
Step 2: Add the Node.js Package Repository:
By default, Rocky Linux does not include the Node.js package in its repositories. To install Node.js, you’ll need to add the NodeSource repository. Run the following commands to add the repository:
sudo dnf install -y curl curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
This will fetch the NodeSource installation script and execute it.
Step 3: Install Node.js:
With the NodeSource repository added, you can now proceed with installing Node.js. Run the following command in the terminal:
sudo dnf install -y nodejs
This command will download and install Node.js along with its npm (Node Package Manager) tool.
Step 4: Verify Node.js Installation:
To confirm that Node.js is installed correctly, run the following commands to check the installed versions:
node --version npm --version
These commands will display the installed versions of Node.js and npm. If you see the version numbers, it indicates that Node.js is installed successfully.
Step 5: Optional – Install Additional Build Tools:
Some Node.js packages may require additional build tools to compile native extensions during installation. To install these build tools, run the following command:
sudo dnf install -y gcc-c++ make
This step is optional but recommended to ensure compatibility with a wide range of Node.js packages.
Conclusion:
Congratulations! You have successfully installed Node.js on your Rocky Linux 9 server. With Node.js, you can build and run server-side JavaScript applications, create APIs, build real-time applications, and much more. Make sure to keep Node.js updated to the latest version and leverage the power of npm to install and manage packages for your projects. Now that you have Node.js up and running, you’re ready to dive into the exciting world of server-side JavaScript development. Happy coding!