Node Version Management


Node Version Manager (NVM) installation in Ubuntu 22.04


Install latest Node Version Manager (NVM)

// current version
https://github.com/creationix/nvm/releases


// installation
$ LATEST_VERSION=$(curl --silent "https://api.github.com/repos/nvm-sh/nvm/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')


// v0.40.3
$ echo $LATEST_VERSION

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/${LATEST_VERSION}/install.sh | bash


CTRL^D, CTRL+ALT+T


$ nvm --version
0.40.3


Install latest Node.js

$ nvm install node
$ nvm use node

$ nvm install-latest-npm

$ npx node -v


Install latest LTS Node.js

// install latest LTS
$ nvm install --lts

$ nvm use --lts

$ node --version
v22.18.0


// WTF ???
$ npx node -v
v22.5.1


$ nvm alias default 22.18.0


$ rm /home/marley/.nvm/versions/node/v22.18.0/bin/npx
$ npm install -g npx

$ node -v
v22.18.0

$ /home/marley/.nvm/versions/node/v22.18.0/bin/npx node -v
v22.5.1

$ which node
/home/marley/.nvm/versions/node/v22.18.0/bin/node

$ which npx
/home/marley/.nvm/versions/node/v22.18.0/bin/npx


$ rm -rf ~/.npm/_npx


$ ls -l $(which node)
$ ls -l $(which npx)

or

-- show possible
$ nvm ls-remote

// (Latest LTS: Erbium)
$ nvm install v12.19.0

$ nvm use v12.19.0

-- set default
$ nvm alias default v12.19.0

$ node --version
v12.19.0


For fast switching

$ {
  nvm install v20.15.0
  nvm use v20.15.0
  nvm alias default v20.15.0
}


$ {
  nvm install v8.17.0
  nvm use v8.17.0
  nvm alias default v8.17.0
}


Install latest NPM

$ nvm install-latest-npm

$ npm --version
11.5.2


Yarn

$ npm install --global yarn


Possible additional configs


packages.json

"engines": {
    "node": ">=12.13.1",
    "npm": ">=6.13.4"
  },


.npmrc

engine-strict=true


// Disable asking for money
$ npm config set fund false --location=global


// Specify registry
$ npm config set registry https://registry.npmjs.org/

$ npm get registry

$ npm config list


// example how to add your repo
$ vi .npmrc

registry=http://mylib.ru:8081/repository/npm-public-repo/


// If yarn will not create node_modules folder create with next content
$ vi .yarnrc.yml
nodeLinker: node-modules