How To Install Node Js On Ubuntu

6 min read

Installing Node.Also, js on Ubuntu is a fundamental skill for any developer working with JavaScript, TypeScript, or modern frontend frameworks like React, Vue, or Next. js. Think about it: because Ubuntu relies on the APT package manager, there are multiple ways to get the runtime onto your system, each offering different levels of version control and stability. Choosing the right method depends entirely on whether you prioritize rock-solid stability for a production server or the flexibility to switch between versions rapidly during local development.

Understanding Your Installation Options

Before typing a single command into the terminal, it helps to understand the three primary pathways available on Ubuntu. Which means finally, Node Version Manager (NVM) is the industry standard for developers who need to manage multiple Node. Practically speaking, the default Ubuntu repositories offer the easiest installation but often provide an outdated version. The NodeSource PPA (Personal Package Archive) gives you access to current Long Term Support (LTS) and Current release lines directly via apt. js versions on a single machine without permission conflicts.

This changes depending on context. Keep that in mind.

Method 1: Installing via NodeSource (Recommended for Servers & CI/CD)

If you are setting up a production server, a CI/CD pipeline, or a Docker container where you need a specific major version (like Node.js 20 LTS or 22 LTS) installed system-wide, the NodeSource repository is the most reliable choice. It integrates natively with apt, allowing for easy updates via standard system maintenance workflows Practical, not theoretical..

Step 1: Update Your Package Index

Always start by refreshing your local package database to ensure you are downloading the latest metadata.

sudo apt update

Step 2: Install Prerequisites

You need ca-certificates, curl, and gnupg to securely add the external repository key.

sudo apt install -y ca-certificates curl gnupg

Step 3: Add the NodeSource Repository

Run the setup script for your desired major version. Replace 20.x with 22.x, 18.x, or lts/* depending on your project requirements. The script automatically detects your Ubuntu codename (e.g., jammy, noble) and configures the sources list No workaround needed..

# Example for Node.js 20 LTS (Iron)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

Using sudo -E preserves environment variables, which is occasionally required for proxy configurations.

Step 4: Install Node.js

Once the repository is added, install the package. This command pulls down both the node binary and npm (Node Package Manager).

sudo apt install -y nodejs

Step 5: Verify the Installation

Confirm the versions installed match your expectations.

node -v
# Expected output: v20.x.x
npm -v
# Expected output: 10.x.x

Pro Tip: If you plan to compile native addons (C++ modules) using node-gyp, install the build tools package:

sudo apt install -y build-essential

Method 2: Installing via NVM (Recommended for Local Development)

For daily development work, NVM (Node Version Manager) is superior. In practice, js inside your user directory (~/. In practice, nvm), meaning you never need sudo to install global packages or switch versions. Still, it installs Node. This avoids permission errors (EACCES) that plague global npm installs on system-managed Node versions.

Step 1: Download and Run the Install Script

Check the for the latest version number (e.g., v0.39.7) and run the install command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Alternatively, use wget if curl is not available.

Step 2: Source Your Shell Configuration

The script attempts to add source lines to your ~/.bashrc, ~/.zshrc, or ~/.profile. To activate NVM immediately in your current terminal session without restarting, run:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Step 3: Install and Manage Versions

Now you can install any version you need. LTS versions are aliased for convenience That's the part that actually makes a difference. Still holds up..

# Install latest LTS (Long Term Support) - currently v20 (Iron) or v22 (Jod)
nvm install --lts

# Install a specific version
nvm install 20.15.0

# List installed versions
nvm list

# List available remote versions
nvm list-remote

# Switch between versions for the current shell
nvm use 20

# Set a default version for new shells
nvm alias default 20

Step 4: Automatic Version Switching with .nvmrc

Create a file named .nvmrc in your project root containing the version number (e.g., 20). When you cd into that directory, you can run nvm use (or configure your shell to auto-switch) to instantly match the project's required runtime. This solves the "works on my machine" problem caused by version mismatches.

Method 3: Installing via Default Ubuntu Repositories (Quick & Dirty)

If you are on a restricted network, building a minimal container, or simply need a JavaScript runtime immediately without external dependencies, the default universe repository works out of the box Turns out it matters..

sudo apt update
sudo apt install -y nodejs npm

Warning: On Ubuntu 22.04 (Jammy), this installs Node.js v12.x, which reached End-of-Life in April 2022. On Ubuntu 24.04 (Noble), it provides a much newer version, but it will still lag behind the official release schedule. Do not use this method for modern application development.

Post-Installation Configuration & Best Practices

Regardless of the installation method chosen, a few configuration steps will drastically improve your developer experience Simple as that..

Configure npm Global Directory (Non-NVM Users Only)

If you installed via NodeSource or APT, global npm install -g commands require sudo by default, which is a security risk and causes permission issues. Fix this by creating a user-owned directory for global packages:

mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'

Add the following to your ~/.profile or ~/.bashrc:

export PATH=~/.npm-global/bin:$PATH

Reload your shell (source ~/.bashrc) and you can now run npm install -g typescript without sudo.

Enable Corepack for Modern Package Managers

Modern Node.js versions ship with Corepack, a tool to manage package managers like Yarn, pnpm, and Bun without installing them globally via npm. Enable it once:

corepack enable

Now yarn, pnpm, and bun commands are available instantly, managed by Node.js itself.

Install TypeScript and Essential Tooling Globally

With your environment ready, install the tools you use across projects:

npm install -g typescript ts-node nodemon @angular/cli @vue/cli create-react-app

*If using NVM

, ensure you are using the desired Node.js version (e.g., nvm use 20) before running global installs, as NVM isolates global modules per Node version Most people skip this — try not to..

Verifying Your Setup

Finally, confirm everything is working correctly:

node --version
npm --version
nvm --version  # If installed via NVM

You should see output matching the versions you installed. To test your package manager, try installing a package globally:

npm install -g create-next-app

Then, verify the tool is accessible:

create-next-app --version

Conclusion

You now have a solid, modern Node.js development environment tailored for professional use. On top of that, by choosing NVM for version management or the NodeSource repository for stable releases, you’ve avoided the pitfalls of outdated system packages. That's why with Corepack enabled and essential tooling installed globally, you’re equipped to build scalable applications efficiently. Remember to regularly update your Node.js version using nvm install --lts (for NVM users) or by checking the Node.js website for new releases to stay current with the ever-evolving JavaScript ecosystem.

Latest Drops

Dropped Recently

Same Kind of Thing

Similar Reads

Thank you for reading about How To Install Node Js On Ubuntu. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home