How to Update Node.js to the Latest Stable Version on AlmaLinux 9

0

Keeping Node.js up to date is essential for accessing the latest features, bug fixes, and performance improvements. If you’re using AlmaLinux 9, a RHEL-based distribution, upgrading Node.js can be straightforward with the right approach. This guide will walk you through the steps to update Node.js to the latest stable version.


Why Update Node.js?

Updating Node.js ensures:

  • Compatibility with the latest libraries and frameworks.
  • Improved security through patched vulnerabilities.
  • Access to new features that enhance developer productivity.

Current Version Check

Before starting, check your current Node.js version:

node -v

For instance, if the output is v18.16.0, you’ll know you’re running an older version.


Steps to Update Node.js on AlmaLinux 9

Follow these simple steps to update Node.js to the latest stable version:

1. Clear npm Cache

Start by cleaning the npm cache to avoid issues during the installation:

sudo npm cache clean -f

2. Install the n Package

The n package is a popular Node.js version manager that simplifies the upgrade process:

sudo npm install -g n

3. Upgrade to the Stable Version

To upgrade to the latest stable version of Node.js, run:

sudo n stable

If you prefer the absolute latest version (which might include non-stable releases), use:

sudo n latest

4. Update the Executable Path

Ensure your shell recognizes the updated Node.js version by refreshing its cache.

For bash, zsh, dash, or ksh:

hash -r

For csh or tcsh:

rehash

5. Verify the Updated Version

Confirm that the upgrade was successful by checking the Node.js version again:

node --version

6. Remove Older Node.js Versions (Optional)

If conflicts arise or older versions linger, remove the old Node.js installation:

sudo dnf remove nodejs

Then, verify the Node.js executable path to ensure it points to the updated version:

which node

This should return /usr/local/bin/node.


Final Checks

1. Verify npm Version

Ensure npm is also updated and using the correct Node.js version:

npm --version

2. Restart the System (if necessary)

If issues persist after the upgrade, restart the terminal or server to apply all changes.


Conclusion

Updating Node.js on AlmaLinux 9 is a straightforward process when using the n package. By following these steps, you’ll ensure that your development environment remains secure, compatible, and up to date. Always verify versions and consider restarting your terminal or system to ensure smooth operation.


Bonus Tip: Automate Future Updates

To stay current with Node.js versions, you can periodically run the following:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

This ensures your environment is always up to date with minimal effort.

Share.

Comments are closed.