unbuntu安装Node.js

时间:2023-09-26 17:24:12

先删除这些

rm -rf ~/.npm

rm -rf ~/.npm-global

rm -rf ~/.npmrc
rm -rf ~/.node-gyp

https://github.com/nodesource/distributions/blob/master/README.md#debinstall

安装

curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs

npm uninstall -g @angular/cli

npm cache clean --force

sudo apt remove nodejs

如果新安装的mint新版本,比如19.2 19.3... node会提示操作系统不支持

形如:

unbuntu安装Node.js

,那么参考https://github.com/nodesource/distributions/issues/881

1 下载nodejs_install.sh

wget -O nodejs_install.sh  https://deb.nodesource.com/setup_13.x

2

xed ./nodejs_install.sh

在文件靠后的地方,找到mint

  

check_alt "Linux Mint"    "tara"     "Ubuntu" "bionic"
check_alt "Linux Mint" "tessa" "Ubuntu" "bionic"

加一行

check_alt "Linux Mint" "tara" "Ubuntu" "bionic"
check_alt "Linux Mint" "tessa" "Ubuntu" "bionic"

check_alt "Linux Mint"    "tricia"     "Ubuntu" "bionic"

形如

unbuntu安装Node.js

然后 保存退出

sudo bash  ./nodejs_install.sh

就可以 安装了

sudo apt-get install -y nodejs

参考这个修改npm路径,以便用-g安装包的时候不报错

  1. Make a directory for global installations:

     mkdir ~/.npm-global
  2. Configure npm to use the new directory path:

     npm config set prefix '~/.npm-global'
  3. xed ~/.profile
  4. Open or create a ~/.profile file and add this line:

     export PATH=~/.npm-global/bin:$PATH
  5. Back on the command line, update your system variables:

     source ~/.profile

添加 PATH="$HOME/.npm-global/bin:$PATH"

再安装angular就不用sudo了

先确认安装了

sudo apt install build-essential

如果不行,就

sudo -i
aptitude install g++

否则sass编译不过,提示没有g++

npm install -g -f @angular/cli

应对被墙, 装nrm

npm i nrm -g

然后用

nrm ls 列出代理

nrm use XXX 切换代理

安装phantomjs

sudo apt-get install phantomjs

安装typescript

npm i -g typescript

查看版本

ng --version

unbuntu安装Node.js

看见Angular: ...应该是安装正确的.

否则会看见error (8.x的node如果没卸载干净安装9  会提示 ts错误)

安装vscode https://code.visualstudio.com/docs/setup/linux

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install code # or code-insiders