一、安装
安装nodejs
1、sudo apt-get install nodejs
安装npm
2、sudo apt-get install npm
查看node版本
node -v
10.8.2
二、卸载
1、sudo apt-get remove --purge nodejs npm
此方法卸载有残留,需要手动清楚残留文件
2、sudo apt-get autoremove --purge nodejs npm
此方法卸载干净
3、dpkg -l | grep nodejs
查看是否有残留
三、部分版本不支持修改镜像源
解决方式:
1. 在nodejs官网下载需要版本
https://nodejs.org/en/download/releases
2. 解压到/usr/local/node中
| 1 2 3 |
|
3. 创建软连接
| 1 2 3 4 5 6 7 |
|
4、修改镜像源
修改镜像源为淘宝镜像:输入以下命令并回车npm config set registry https://registry.npmmirror.com
修改镜像源为腾讯镜像源:输入以下命令并回车npm config set registry http://mirrors.cloud.tencent.com/npm/
修改镜像源为华为镜像源:输入以下命令并回车npm config set registry
https://mirrors.huaweicloud.com/repository/npm/
最后通过命令npm config get registry查看仓库镜像源是否修改成功
5、npm安装查看速度变快了

6、配置环境变量
第一步:使用命令找到nodejs安装的路径,npm prefix -g
第二步:su root,cd /etc,然后,vim ./profile # 输入node/bin的绝对路径 export PATH=/home/hkl/hkl/node/bin:$PATH,/home/hkl/hkl/node/bin这个是自己安装nodejs的路径加上bin目录,我的安装路径,
所以是/home/hkl/hkl/node/bin
第三步::wq,保存退出后,执行:source /ect/profile,再次执行http-server命令,即可成功
5099

被折叠的 条评论
为什么被折叠?



