Skip to content
Search Fedora

    Browse this documentation

    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.

    Terminal window
    sudo dnf install nodejs npm

    Measured on F45:

    nodejs-22.23.1-4.fc45.x86_64

    Verify:

    Terminal window
    node -v
    npm -v
    v22.23.1
    10.9.8

    One line to confirm V8 as well:

    Terminal window
    node -e "console.log(process.versions.v8)"
    12.4.254.21-node.56

    Where the npm global prefix points (important)

    Section titled “Where the npm global prefix points (important)”
    Terminal window
    npm config get prefix
    /usr/local

    Which means npm install -g writes to /usr/local/lib/node_modules and needs sudo:

    Terminal window
    sudo npm install -g pnpm

    Moving the global directory into your home

    Section titled “Moving the global directory into your home”
    Terminal window
    mkdir -p ~/.npm-global
    npm config set prefix ~/.npm-global
    echo 'export PATH=$HOME/.npm-global/bin:$PATH' >> ~/.bashrc
    source ~/.bashrc

    Now npm install -g needs no sudo:

    Terminal window
    npm install -g pnpm
    pnpm -v

    This writes ~/.npmrc; remember to back it up alongside your other dotfiles.

    Terminal window
    mkdir -p ~/hello && cd ~/hello
    npm init -y
    node -e "console.log('node', process.version)"

    Install a dependency and start a server:

    Terminal window
    npm install express
    cat > 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'));
    EOF
    node server.js

    In another terminal:

    Terminal window
    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:

    Terminal window
    sudo dnf install nodejs24 nodejs26

    Versioned executables appear in /usr/bin:

    Terminal window
    ls /usr/bin | grep -E "^node"
    node
    node-22
    node-24
    node-26

    Each reports its own version:

    Terminal window
    node -v # v22.23.1 <- default
    node-24 -v # v24.18.0
    node-26 -v # v26.3.1

    npm follows the same pattern:

    Terminal window
    ls /usr/bin | grep -E "^npm"
    npm
    npm-22
    npm-24
    npm-26

    They share one global prefix (/usr/local), but npm-24 install -g resolves to the Node 24 runtime.

    PackageBinaries providedMeasured version
    nodejs (default)node, node-22v22.23.1
    nodejs24node-24v24.18.0
    nodejs26node-26v26.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.

    Fedora packages exactly one version (22 on F45). For 20 or 18:

    MethodFits
    versioned packages such as dnf install nodejs22easiest when the repo offers one
    containers: podman run --rm node:20 node -vbuilds and tests
    nvmswitching versions on a dev machine
    Terminal window
    dnf search nodejs | grep -E "^nodejs[0-9]+" # look for versioned packages
    podman run --rm node:20-alpine node -v

    Avoid third-party repositories (NodeSource and friends) that overwrite the system nodejs — the next dnf upgrade tends to produce file conflicts.

    SymptomCause
    npm install -g fails with EACCESthe global prefix /usr/local belongs to root; change the prefix or use sudo
    command not found: nodeinstalled but the shell has not reloaded PATH
    a project needs a newer Noderepository version lags; use a container or nvm
    globally installed package has no commandprefix changed but ~/.npm-global/bin missing from PATH