How to install Node.js on Ubuntu - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

How to install Node.js on Ubuntu
================================

### [\#Development](https://rocketeersapp.com/knowledge/development)

Modern PHP sites still need Node.js to build their frontend assets. Here is how to install Node.js on Ubuntu with nvm, so you can switch versions per project without touching the system.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on June 30, 2026 · 1 minute read

1. [Install nvm](#content-install-nvm)
2. [Install Node.js](#content-install-nodejs)
3. [Switch versions per project](#content-switch-versions-per-project)
4. [Building assets on deploy](#content-building-assets-on-deploy)
5. [The alternative: NodeSource](#content-the-alternative-nodesource)
6. [Let Rocketeers handle it](#content-let-rocketeers-handle-it)

Even a PHP application usually needs Node.js — to compile CSS, bundle JavaScript with Vite or webpack, and run the asset build step during [deployment](/zero-downtime-php-deployments). The cleanest way to install it is [nvm](https://github.com/nvm-sh/nvm), the Node Version Manager, which keeps Node in your home directory so different projects can run different versions without `sudo`.

[\#](#content-install-nvm "Permalink")Install nvm
-------------------------------------------------

Run the official install script (pin it to a specific nvm version so the install is reproducible):

 ```
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash

```

The script appends the loader to your shell profile. Either open a new shell or load it into the current one:

 ```
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

```

Confirm it's available:

 ```
nvm --version

```

[\#](#content-install-nodejs "Permalink")Install Node.js
--------------------------------------------------------

Install the version you want and set it as the default for new shells:

 ```
nvm install 22
nvm alias default 22

```

Check both Node and npm came along:

 ```
node -v
npm -v

```

[\#](#content-switch-versions-per-project "Permalink")Switch versions per project
---------------------------------------------------------------------------------

The whole point of nvm is that one server can run several Node versions. Install another and switch with a single command:

 ```
nvm install 20
nvm use 20

```

Drop a `.nvmrc` file containing a version number (for example `22`) in a project's root and `nvm use` will pick it up automatically — handy for keeping a deploy script on the right version.

[\#](#content-building-assets-on-deploy "Permalink")Building assets on deploy
-----------------------------------------------------------------------------

In a deployment you'll typically install dependencies and run a build:

 ```
npm ci
npm run build

```

Use `npm ci` rather than `npm install` on a server — it's faster and installs exactly what's in the lockfile. The difference matters more than it looks; see [npm ci vs npm install](/npm-ci-vs-npm-install).

[\#](#content-the-alternative-nodesource "Permalink")The alternative: NodeSource
--------------------------------------------------------------------------------

If you'd rather install Node system-wide (every user, no per-shell loading), the NodeSource apt repository is the common alternative. nvm wins when you need multiple versions or want to avoid `sudo`; NodeSource wins for a single fixed version on a dedicated box.

[\#](#content-let-rocketeers-handle-it "Permalink")Let Rocketeers handle it
---------------------------------------------------------------------------

Installing nvm, loading it in the right shell profile, pinning versions per project, and making sure the deploy step runs with the correct Node version is one more moving part to keep aligned. Rocketeers installs Node.js during provisioning and runs your asset build as part of every deployment — so the frontend is compiled and live without a separate setup.

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Development](https://rocketeersapp.com/knowledge/development)

- [Install PHP memcached extension on macOS](https://rocketeersapp.com/knowledge/install-php-memcached-extension-on-macos)
- [git stash pop vs apply: save and restore changes](https://rocketeersapp.com/knowledge/git-stash-pop)
- [npm ci vs npm install: when to use which](https://rocketeersapp.com/knowledge/npm-ci-vs-npm-install)
- [How to delete a local (and remote) Git branch](https://rocketeersapp.com/knowledge/git-delete-local-branch)
- [docker compose up: options and common flags](https://rocketeersapp.com/knowledge/docker-compose-up)
- [How to checkout a Git tag](https://rocketeersapp.com/knowledge/git-checkout-tag)

 [View all 13 articles →](https://rocketeersapp.com/knowledge/development)
