Node.js can be installed in several ways, and the method you choose has real consequences for how you manage it day to day. Installing directly from the Node.js website is the simplest path, but it is rarely the best one for a developer. Understanding the options — and why version management matters — will save you significant friction.
Node.js Versioning
Before installing, it is worth understanding how Node.js releases are structured.
Node.js follows a predictable release cycle. Even-numbered versions — Node.js 18, 20, 22 — are LTS (Long-Term Support) releases. They receive active maintenance for 18 months after release, followed by a further 12 months of security updates. These are the versions intended for production use and serious development work.
Odd-numbered versions — Node.js 19, 21, 23 — are Current releases. They introduce new features and are maintained for only six months before being superseded. They are not intended for production.
| Release type | Example | Maintenance period | When to use |
|---|---|---|---|
| LTS | Node.js 22 | ~30 months total | Production, stable development |
| Current | Node.js 23 | 6 months | Trying new features |
For most development work, install the latest LTS version.
Installation Methods
Direct Installation from nodejs.org
The Node.js website at nodejs.org provides installers for Windows, macOS, and Linux. This is the most straightforward method — download the installer, run it, and Node.js is available on your machine.
The limitation is that you get a single version of Node.js installed globally. If you work on multiple projects that require different versions — one project on Node.js 18, another on Node.js 22 — this becomes a problem. You would need to uninstall and reinstall every time you switch.
For this reason, direct installation is not recommended for developers. Use a version manager instead.
Installing with a Version Manager — nvm (macOS and Linux)
A version manager lets you install multiple versions of Node.js and switch between them instantly. The most widely used version manager on macOS and Linux is nvm (Node Version Manager).
Installing nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
This downloads and runs the nvm install script. It installs nvm into ~/.nvm and adds the necessary configuration to your shell profile (.bashrc, .zshrc, or .profile depending on your shell).
After installation, restart your terminal or run the following to load nvm in the current session:
source ~/.bashrc # if using bash
source ~/.zshrc # if using zsh
Verify the installation:
nvm --version
Installing Node.js with nvm
Install the latest LTS version:
nvm install --lts
Install a specific version:
nvm install 20
nvm install 22.3.0
List all installed versions:
nvm ls
Output:
v18.20.4
-> v20.14.0
v22.3.0
default -> lts/* (-> v20.14.0)
The arrow indicates the currently active version. default shows which version nvm will use when you open a new terminal session.
Switch to a different version:
nvm use 22
Set a default version for all new terminal sessions:
nvm alias default 20
The .nvmrc File
A .nvmrc file in the root of a project specifies which Node.js version that project requires. When you navigate into the project directory and run nvm use, nvm reads the file and switches to the specified version automatically.
Create a .nvmrc file:
echo "20" > .nvmrc
Use the version specified in .nvmrc:
nvm use
# Found '/home/wariz/my-project/.nvmrc' with version <20>
# Now using node v20.14.0
This is the correct way to pin a Node.js version for a project and communicate that requirement to other developers working on the same codebase.
Installing with a Version Manager — fnm (Windows, macOS, Linux)
fnm (Fast Node Manager) is a newer version manager written in Rust. It is significantly faster than nvm and has first-class support for Windows — something nvm historically lacked.
Install fnm on macOS with Homebrew:
brew install fnm
Install fnm on Windows with winget:
winget install Schniz.fnm
After installation, add the fnm shell hook to your shell profile. For zsh:
eval "$(fnm env --use-on-cd)"
The core commands mirror nvm closely:
fnm install --lts # install the latest LTS version
fnm install 22 # install a specific version
fnm use 20 # switch to a version
fnm default 20 # set a default version
fnm ls # list installed versions
fnm also supports .nvmrc and .node-version files, making it a drop-in replacement for nvm with faster performance.
Installing on Windows — Without a Version Manager
If you are on Windows and prefer not to use fnm, the Node.js website provides a standard .msi Windows installer. Run it, follow the prompts, and Node.js will be available in Command Prompt and PowerShell.
The same limitation applies as with direct installation on any platform: you get one version, and switching requires a manual reinstall. fnm is the better choice on Windows.
Verifying the Installation
After installing Node.js by any method, verify that both Node.js and npm are available:
node --version
Output:
v20.14.0
npm --version
Output:
10.7.0
npm is bundled with Node.js — installing Node.js installs npm automatically. You do not need to install npm separately.
Configuring Node.js
Node.js itself has very little global configuration. Unlike some runtimes, there is no central config file you need to maintain. Most configuration in Node.js happens at the project level, not the system level.
That said, there are a few things worth setting up.
npm Configuration
npm — which ships with Node.js — has its own configuration system managed through the npm config command. The configuration is stored in a .npmrc file.
View your current npm configuration:
npm config list
The most commonly configured options:
| Setting | Command | What It Does |
|---|---|---|
init-author-name | npm config set init-author-name "Your Name" | Pre-fills the author name when running npm init |
init-author-email | npm config set init-author-email "you@example.com" | Pre-fills the author email |
init-license | npm config set init-license "MIT" | Sets the default licence for new packages |
save-exact | npm config set save-exact true | Saves exact package versions instead of ranges |
These are stored globally in ~/.npmrc and apply to every project on your machine.
Setting the Default Node.js Version
When using nvm or fnm, you should always set a default version so that new terminal sessions have access to Node.js:
# With nvm
nvm alias default 20
# With fnm
fnm default 20
Without this, opening a new terminal may show node: command not found even though you have Node.js installed.
Environment Variables
Node.js recognises a small number of environment variables that affect its behaviour at startup:
| Variable | What It Controls |
|---|---|
NODE_ENV | The runtime environment — typically development, test, or production |
NODE_PATH | Additional directories to search when resolving modules |
UV_THREADPOOL_SIZE | The number of threads in libuv's thread pool (default: 4) |
NODE_OPTIONS | Default CLI flags to apply to every Node.js process |
NODE_ENV is the most commonly used. Many libraries — including Express — change their behaviour based on its value. Setting NODE_ENV=production typically disables development-only features, enables caching, and reduces verbose logging.
These variables are set in your shell or in a .env file at the project level, not in any Node.js system config.
Updating Node.js
With nvm
nvm install --lts # installs the latest LTS
nvm alias default --lts # sets it as the default
nvm uninstall 18 # removes an old version
With fnm
fnm install --lts
fnm default lts-latest
Migrating Global npm Packages
When you install a new version of Node.js, globally installed npm packages are not automatically carried over. With nvm, you can migrate them from the previous version:
nvm install 22 --reinstall-packages-from=20
This installs Node.js 22 and reinstalls every global npm package that was installed under Node.js 20.
Checking What Is Installed
At any point, you can see the current Node.js version, npm version, and the path of the active Node.js binary:
node --version # Node.js version
npm --version # npm version
which node # path to the active node binary
which npm # path to the active npm binary
If you are using nvm:
nvm current # the currently active version
nvm ls # all installed versions
Summary
| Task | Command |
|---|---|
| Install nvm | `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh |
| Install latest LTS (nvm) | nvm install --lts |
| Install latest LTS (fnm) | fnm install --lts |
| Switch Node.js version | nvm use <version> / fnm use <version> |
| Set default version | nvm alias default <version> / fnm default <version> |
| Pin version for a project | echo "<version>" > .nvmrc |
| Verify installation | node --version and npm --version |
| View npm config | npm config list |