完全卸载nodejs
apt remove nodejs npm -y
bash# 删除node.node_modules文件夹
rm -rf /usr/local/lib/node*
rm -rf /usr/local/include/node*
rm -rf /usr/local/node*
bash# 查找并删除~文件夹里的node和node_modules文件夹
find ~/ -name node
find ~/ -name node_modules
# 使用rm -rf 命令删除对应结果
bash# 删除node可执行文件
rm -rf /usr/local/bin/npm
rm -rf /usr/local/share/man/man1/node.1
rm -rf /usr/local/lib/dtrace/node.d
rm -rf ~/.npm
rm -rf /usr/bin/node
rm -rf /usr/bin/npm
bash# 下载解压nodejs
wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz
tar -zxvf node-v12.13.0-linux-x64.tar.xz
建立软链接
sudo ln -s /opt/modules/node-v6.17.1-linux-x64/bin/node /usr/bin/node
sudo ln -s /opt/modules/node-v6.17.1-linux-x64/bin/npm /usr/bin/npm
node -v npm -v
sudo apt update sudo apt -u upgrade 12
sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt -y install nodejs sudo apt install gcc g++ make 12
命令行版本确认
$ node --version v12.10.0 $ npm --version 6.10.3 12345
代码运行验证, 测试代码 hello-world.js
jsconst http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at https://${hostname}:${port}/`);
});
1234567891011121314
运行代码
shellnode hello-world.js 1
打开浏览器就可以看到“hello world!”
refers:
本文作者:墨洺的文档
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!