在linux上安装Node.js
一、安装nvm
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/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 install $version
$version代表你想安装的版本
以20为例
nvm install 20
四、检查
nvm
nvm --version
node.js
node --version
npm
npm --version
| 推荐的nodejs 包管理器 | npm包形式 | ||
|---|---|---|---|
| yarn | corepack prepare yarn@stable –activate | corepack prepare yarn@ |
npm install –global yarn |
| pnpm | curl -fsSL -qO- https://get.pnpm.io/install.sh | bash | wget -qO- https://get.pnpm.io/install.sh |bash | npm install –global pnpm |
| bun | curl -fsSL https://bun.sh/install | bash | wget -qO- https://bun.sh/install | bash | npm install –global bun |