To install Node.js on Rocky Linux, use the distribution’s DNF package manager with either Rocky’s available AppStream modules or a trusted third-party Node.js repository. For the newest supported release line, the Node Version Manager (nvm) project is another option; choose based on whether you need a system-wide installation or separate Node.js versions for a user account.
Choose an installation method
Rocky Linux is an Enterprise Linux distribution, so its software is commonly delivered through DNF repositories and AppStream modules. The Node.js version available there depends on the Rocky Linux release and enabled repositories. It may be older than the current upstream release, but it is managed in the familiar system package workflow.
- DNF/AppStream: A good fit for servers and system-managed software. Packages are installed and updated through DNF.
- NodeSource packages: A repository-based option for selecting a supported Node.js major line when it is not conveniently available in the enabled Rocky repositories. Follow the repository’s current instructions for your operating system and version.
- nvm: Useful for development accounts that need to switch between Node.js versions. It installs versions under a user’s home directory rather than providing a machine-wide package.
Avoid combining methods casually. Installing Node.js through DNF and then installing another copy with nvm can leave multiple executables on the machine; the command found first in a user’s PATH determines which one runs.
Install Node.js with DNF
First check the Rocky Linux release and available Node.js packages. These commands do not change the system:
cat /etc/rocky-release
sudo dnf search nodejs
sudo dnf module list nodejs
On systems where DNF presents Node.js as a module, inspect the listed streams before enabling one. A stream represents a package version line; available streams vary by Rocky release and repository configuration. To select a listed stream, substitute its exact name for <stream> below:
sudo dnf module enable nodejs:<stream>
sudo dnf install nodejs
If DNF reports that modular filtering or a missing stream prevents installation, do not guess a stream name. Check the output of dnf module list nodejs and the release’s enabled repositories. On a system where the package is available directly without a module choice, installing it may simply be:
sudo dnf install nodejs
DNF will show the packages and dependencies it plans to add; review the transaction before confirming. The Node.js package commonly includes npm, but verify rather than assuming:
node --version
npm --version
The node command is the JavaScript runtime. npm is the package manager commonly used to install project dependencies. If the shell says either command is not found, check whether installation completed successfully and whether the package source actually provides that command.
Install a newer major release from a repository
If Rocky’s enabled repositories do not provide the Node.js major version your project needs, a third-party RPM repository can be an alternative. NodeSource is a commonly used source of Node.js RPM packages, but repository setup instructions and supported release lines can change. Use the current instructions published by the repository for Rocky Linux or its compatible Enterprise Linux version; do not copy an old setup command from an unrelated release.
Before adding a repository, confirm that its instructions match your Rocky release and architecture. A repository setup typically adds a repository configuration, after which DNF installs the package:
sudo dnf install nodejs
That install command alone does not select or configure a repository. Follow the repository’s documented setup first, then inspect DNF’s proposed transaction. Avoid mixing RPM packages from incompatible distributions or installing a package with an arbitrary download command: package provenance and compatibility matter, particularly on a server.
Use nvm for per-user versions
nvm is often more convenient when a developer must test projects against different Node.js releases. Install it as the account that will use Node.js, following the current instructions in the nvm project’s official repository. Open a new shell or load the shell configuration as instructed, then install a version:
nvm install --lts
nvm use --lts
node --version
npm --version
The LTS alias selects the latest long-term support release known to the installed nvm version; it does not mean the same fixed version forever. You can install a specific major version when a project requires it, and use nvm’s commands to switch between installed versions. Check a project’s README or its package.json before choosing: compatibility requirements can be more important than simply selecting the newest release.
Because nvm modifies a user’s shell environment, Node.js installed this way may not be available to services started by systemd or to other user accounts. Do not assume a service can see an interactive user’s nvm-managed executable. For machine-wide services, use a deployment approach that explicitly configures the service’s executable path and runtime environment.
Verify installation and manage updates
After installation, check which executable the shell will run and where it is located:
node --version
npm --version
command -v node
command -v npm
Use DNF to update an RPM-managed installation when package updates are available:
sudo dnf check-update
sudo dnf upgrade nodejs
Depending on repository configuration, a general sudo dnf upgrade may be more appropriate for routine system updates. With nvm, update by installing and selecting the desired version through nvm rather than expecting DNF to manage it. Keep track of which method installed the active executable so that updates reach the copy your applications actually use.
For a quick runtime test, run a small JavaScript expression:
node -e 'console.log("Node.js is working")'
This confirms that Node.js can start; it does not test a web application, its dependencies, or network access.
Common problems and practical checks
- No package found: Check the Rocky release, enabled repositories, and the output of
dnf search nodejs. A package name or module stream may not be available in the repositories currently enabled. - Wrong version: Compare
node --versionwith the version required by the project. Check for multiple installations withcommand -v nodeand inspect the PATH before removing packages. - npm is missing: Confirm whether the selected package includes npm and consult that repository’s package information. Do not assume a separate package name is identical across all sources.
- Permission errors installing global npm packages: Avoid reflexively using
sudo npm install -g. Global installs with elevated privileges can create ownership and security problems. For development, consider project-local dependencies or a user-managed version manager. - nvm works in a terminal but not in a service: The service likely does not load the interactive shell configuration. Configure the service to use an intentional runtime path, or use a system-managed installation appropriate to the deployment.
Node.js itself does not require opening a firewall port. A Node.js application that listens for network connections may need separate service, firewall, and access configuration; installing the runtime does not expose an application automatically.
Frequently Asked Questions
Is Node.js available in Rocky Linux’s default repositories?
Availability and version depend on the Rocky release and enabled repositories. Check with dnf search nodejs and dnf module list nodejs rather than relying on a version reported for another Rocky release.
Should I use DNF or nvm?
Use DNF when you want a system-managed package maintained through RPM updates. Use nvm when one user needs to install or switch among multiple Node.js versions. Avoid mixing them unless you understand which executable takes precedence.
Does installing Node.js also install npm?
Many Node.js package installations include npm, but package contents vary. Run npm --version after installation and check the package documentation if the command is missing.
How can I install a specific Node.js version?
With nvm, install the required version using its version-selection commands. With DNF or a third-party repository, use only a stream or package source documented as available for your Rocky release.
Can I use an nvm installation for a systemd service?
It is possible to configure a service to use a user-managed runtime, but a service does not normally inherit an interactive shell’s PATH. Set and maintain the executable path explicitly, or use a system-wide deployment method.
Do I need to reboot after installing Node.js?
Usually not. Open a new shell if necessary, especially after changing shell configuration for nvm, then verify the active commands with node --version and command -v node.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix Error 0x80072f76 0x20016 in Windows
- How to Backup and Restore Drivers in Windows 11
- Fix Windows Couldn’t Complete the Requested Changes
- Move to iOS Stuck? Fixes That Actually Work
- USB Bluetooth Dongle: What It Is and How It Works
- ADB Device Not Found Error on Windows: Fixed