Installing Node.js on Fedora: 22 LTS and the npm global-prefix trap
Node.js on Fedora comes from the distribution repositories. The version follows Fedora rather than upstream — which is exactly why it is stable.
Install
Section titled “Install”sudo dnf install nodejs npmMeasured on F45:
nodejs-22.23.1-4.fc45.x86_64Verify:
node -vnpm -vv22.23.110.9.8One line to confirm V8 as well:
node -e "console.log(process.versions.v8)"12.4.254.21-node.56Where the npm global prefix points (important)
Section titled “Where the npm global prefix points (important)”npm config get prefix/usr/localWhich means npm install -g writes to /usr/local/lib/node_modules and needs sudo:
sudo npm install -g pnpmMoving the global directory into your home
Section titled “Moving the global directory into your home”mkdir -p ~/.npm-globalnpm config set prefix ~/.npm-globalecho 'export PATH=$HOME/.npm-global/bin:$PATH' >> ~/.bashrcsource ~/.bashrcNow npm install -g needs no sudo:
npm install -g pnpmpnpm -vThis writes ~/.npmrc; remember to back it up alongside your other dotfiles.
Running a project
Section titled “Running a project”mkdir -p ~/hello && cd ~/hellonpm init -ynode -e "console.log('node', process.version)"Install a dependency and start a server:
npm install expresscat > server.js <<'EOF'const express = require('express');const app = express();app.get('/', (req, res) => res.send('ok from ' + process.version));app.listen(3000, () => console.log('listening on 3000'));EOFnode server.jsIn another terminal:
curl -s http://127.0.0.1:3000/Multiple versions: Fedora ships 22 / 24 / 26 natively
Section titled “Multiple versions: Fedora ships 22 / 24 / 26 natively”This is the most overlooked part of Node on Fedora — you do not need nvm; the repositories carry several Nodes side by side:
sudo dnf install nodejs24 nodejs26Versioned executables appear in /usr/bin:
ls /usr/bin | grep -E "^node"nodenode-22node-24node-26Each reports its own version:
node -v # v22.23.1 <- defaultnode-24 -v # v24.18.0node-26 -v # v26.3.1npm follows the same pattern:
ls /usr/bin | grep -E "^npm"npmnpm-22npm-24npm-26They share one global prefix (/usr/local), but npm-24 install -g resolves to the Node 24 runtime.
| Package | Binaries provided | Measured version |
|---|---|---|
nodejs (default) | node, node-22 | v22.23.1 |
nodejs24 | node-24 | v24.18.0 |
nodejs26 | node-26 | v26.3.1 |
When nvm is still the right answer: you need a non-major version (say 16.20.2), you switch often and dislike remembering suffixes, or you need an EOL release (14/16). Fedora only packages the currently supported majors.
Needing a different Node version
Section titled “Needing a different Node version”Fedora packages exactly one version (22 on F45). For 20 or 18:
| Method | Fits |
|---|---|
versioned packages such as dnf install nodejs22 | easiest when the repo offers one |
containers: podman run --rm node:20 node -v | builds and tests |
| nvm | switching versions on a dev machine |
dnf search nodejs | grep -E "^nodejs[0-9]+" # look for versioned packagespodman run --rm node:20-alpine node -vAvoid third-party repositories (NodeSource and friends) that overwrite the system nodejs — the next dnf upgrade tends to produce file conflicts.
Common traps
Section titled “Common traps”| Symptom | Cause |
|---|---|
npm install -g fails with EACCES | the global prefix /usr/local belongs to root; change the prefix or use sudo |
command not found: node | installed but the shell has not reloaded PATH |
| a project needs a newer Node | repository version lags; use a container or nvm |
| globally installed package has no command | prefix changed but ~/.npm-global/bin missing from PATH |
Related pages
Section titled “Related pages”- Toolchain and multiple versions — beyond Node
- Containers and rootless — pinning a Node version
- firewalld — opening service ports
- Repositories and dnf5 — package basics
- Official: Node.js