Introduction
Node.js is a critical component of modern backend applications. Keeping the runtime up to date helps applications remain compatible with dependencies, receive ongoing security fixes, and benefit from improvements in the JavaScript runtime.
Upgrading Node.js 20 to 24 on a Linux server requires careful planning, particularly when applications are managed using NVM and PM2. A successful upgrade involves installing the new runtime, checking application compatibility, updating process management configurations, and verifying that applications continue to run correctly.
The objective was to install Node.js v24.22.1, preserve the existing version for rollback, and ensure that PM2-managed applications and future deployments consistently use the new runtime.
How do you upgrade Node.js 20 to 24 on a Linux server?
You can upgrade Node.js 20 to 24 on a Linux server using NVM (Node Version Manager). Install the required Node.js version, switch the active runtime, update PM2 configurations, restart applications, and verify their functionality. Always check dependency compatibility and maintain a rollback plan before making changes to a production server.
1. Understanding the existing environment
The application server used the following stack:
- Operating system: Linux
- Runtime manager: NVM for Linux
- Existing Node.js version: v20.19.6
- Target Node.js version: v24.22.1
2. Installing Node.js v24 using NVM
NVM allows multiple Node.js versions to coexist on the same machine. This is useful when maintaining legacy applications while preparing a newer runtime. First, verify that NVM is available:
| command -v nvm nvm ls |
Install the required version:
| nvm install 24.22.1 |
Verify that it is installed:
| nvm ls nvm exec 24.22.1 node -v nvm exec 24.22.1 npm -v |
The Node.js version command should return: v24.22.1
At this stage, Node.js v20.19.6 remains installed. Installing v24 does not automatically change the runtime of an application that is already running.
3. Changing the default Node.js version
After verifying the installation, the default NVM version can be changed:
| nvm alias default 24.22.1 |
Verify the active version and executable path on another shell:
| node -v which node |
Expected output includes:
| v24.22.1 /root/.nvm/versions/node/v24.22.1/bin/node |
4. Restart Your Application and Monitor Logs
After upgrading Node.js, restart your application to ensure it runs on the new runtime. The restart method depends on how your application is managed.
If you manage your application with PM2 in cluster mode, you can use:
| pm2 reload my-app |
Monitor application logs for the first few minutes after the restart to catch startup failures, dependency issues, or runtime errors.
Look for errors such as missing modules, incompatible dependencies, configuration problems, failed database connections, or unexpected process exits. Finally, verify the application’s health endpoint and test its critical functionality.
5. Conclusion
Upgrading Node.js from v20 to v24 involves more than installing a new runtime. In an environment using NVM, PM2, and automated deployments, the interactive shell, PM2 daemon, and deployment pipeline can each have different runtime configurations.
The key lesson is to configure the intended Node.js version explicitly, validate it at the process level, and test the application after restarting it.
A controlled upgrade, a verified deployment pipeline, and a tested rollback plan help make the transition safer and more repeatable across development, SIT, UAT, and production environments.
Need Professional Help with Node.js Server Management?
Managing Node.js applications in production requires more than routine version upgrades. Runtime compatibility, dependency management, process monitoring, deployment configurations, and server stability all need proper attention.
An improperly managed upgrade can lead to application downtime, unexpected errors, and deployment failures.
Skynats provides professional server management and cloud infrastructure support to help businesses maintain secure, stable, and reliable server environments.
Whether you are planning a Node.js upgrade, managing production applications, or facing server performance and compatibility issues, our team can help you manage your infrastructure requirements.
Need assistance with your server environment? Contact Skynats for professional server management support
