mynote/nodejs/install.md
2024-10-14 19:21:13 +08:00

66 lines
1.2 KiB
Markdown

# install nodejs npm
- refer to https://segmentfault.com/a/1190000007542620
## nvm
```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm list-remote
nvm install node
npm install --global yarn
```
### install and update
``` bash
sudo apt install nodejs
sudo apt install npm
sudo npm install n@latest -g
sudo n stable
sudo npm install npm@latest -g
node -v
npm -v
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
#or
npm config set registry https://registry.npm.taobao.org
npm config get registry
```
- if error: /usr/bin/env: node: No such file or directory
> ln -s /usr/bin/nodejs /usr/bin/node
- if old nodejs still exist
> sudo apt purge nodejs
### node && yarn
```bash
# yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
sudo yarn global add n
sudo n stable
```
### nvm
```bash
https://github.com/nvm-sh/nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install 20
npm install --global yarn
```