(mac brew + linux) install npm (node.js)

date
Apr 14, 2022
slug
tip-brew-npm
status
Published
summary
小技巧
tags
tip
type
Post
URL

Problem & Summary

  • use brew to install first, then use npm to upgrade itself

Solution

Mac - brew

brew install npm
npm upgrade -g npm

npm doctor
# chmod +x /usr/local/bin/.keepme

Linux Ubunu

# 默认安装老版本
apt install -y nodejs npm

# (推荐)安装新版本
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
apt install -y nodejs # 自动安装npm
node --version && npm --version

通过NVM安装(可以装多个不同版本)

notion image
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
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
nvm --version
nvm list-remote # get a list of all Node.js versions that can be installed with nvm
nvm install node # install the latest
# install two more versions, the latest LTS version and version 10.9.0:
nvm install --lts
nvm install 10.9.0

# change the currently active version
nvm use 12.16.3
# change the default Node.js version
nvm alias default 12.16.3

© Ying Bun 2021 - 2024