In this guide, we will show you, how to install Node.js on Almalinux. It is an open-source JavaScript runtime built on Chrome’s V8 JavaScript engine. Nodejs also provides an event-driven architecture and non-blocking I/O that is optimized & scalable.
There are thousands of open-source libraries for Node.js, most of them hosted on the npm website. Node.js is also a cross-platform server environment that can run on Windows, Linux, Unix, macOS, and more. Let’s get started with the installation.
Prerequisites
- A server with Almalinux as OS
- User privileges: root or non-root user with sudo privileges
1. Login to your VPS via SSH
# ssh user@vps_IP
2. Update the system and install the necessary packages
# yum -y update
# yum install curl
3. Install Node.js from the NodeSource repository
You can use the following command to install Nodejs 18 using the nodesource repository.
# curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo -E bash -
after the installation is completed you can check if the nodejs is installed by running the command:
# node -v
4. Install Nodejs using yum package manager
To check which nodejs versions are available you can use the command:
# yum module list nodejs
You should see an output similar to this
Last metadata expiration check: 0:05:17 ago on Thu 12 Jan 2023 10:30:56 AM CST. AlmaLinux 8 - AppStream Name Stream Profiles Summary nodejs 10 [d] common [d], development, minimal, s2i Javascript runtime nodejs 12 common [d], development, minimal, s2i Javascript runtime nodejs 14 common [d], development, minimal, s2i Javascript runtime nodejs 16 [e] common [d], development, minimal, s2i Javascript runtime nodejs 18 common [d], development, minimal, s2i Javascript runtime Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
As you can see there are several versions which are available to install, you can choose the version you want to install on your system and proceed with the installation with the following command:
# yum module install nodejs:18
You will get the following result, where you should enter ‘y’ and click enter to continue the installation:
# yum module install nodejs:18
Last metadata expiration check: 3:12:10 ago on Thu 12 Jan 2023 01:44:08 PM CST. Dependencies resolved. ================================================================================ Package Arch Version Repo Size ================================================================================ Installing group/module packages: nodejs x86_64 1:18.12.1-2.module_el8.7.0+3370+40ccb2a8 appstream 13 M npm x86_64 1:8.19.2-1.18.12.1.2.module_el8.7.0+3370+40ccb2a8 appstream 2.0 M Installing weak dependencies: nodejs-docs noarch 1:18.12.1-2.module_el8.7.0+3370+40ccb2a8 appstream 9.5 M nodejs-full-i18n x86_64 1:18.12.1-2.module_el8.7.0+3370+40ccb2a8 appstream 8.0 M Installing module profiles: nodejs/common Enabling module streams: nodejs 18 Transaction Summary ================================================================================ Install 4 Packages Total download size: 33 M Installed size: 161 M Is this ok [y/N]: y
Once the installation has been completed, you can check if nodejs is installed and which version:
# node -v
For testing purposes, you can run a basic Hello World code in nodejs.
You will need to create a new file with whichever name you want just make sure to use the .js extension at the end, for example helloworld.js
# nano helloworld.js
Next you can copy the Nodejs from here:
const http = require('http'); const hostname = '0.0.0.0'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World'); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); });
Then simply run the Nodejs code with:
# node helloworld.js
You should get the following output.
Server running at http://0.0.0.0:3000/
If you now go on your favorite browser and visit YOUR_IP_ADDRESS:3000 you should be able to see “Hello World,” which verifies that the nodejs is properly installed and running on port 3000.
We believe our post today has successfully guided you on how to install Node.js on AlmaLinux without any hassles.
We’re now eager to hear your thoughts. Did we skip something you think is important, or is there any step that you need more explanation on?
Are there any other subjects or tutorials you wish we’d focus on next?
Whatever your thoughts are, we’d love to hear from you in the comments below.
Great post. Been struggling with how to do this for hours. This helped! 🙂
Thanks so much. This works perfect!!!
Great guide on installing Node.js on AlmaLinux!