51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

nodejs安装(linux)-npm 命令

npm 命令

npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/

npm install --registry=https://registry.npm.taobao.org

npm run build

查看版本:

node -v 
npm -v

nodejs 设置仓库(缓存-镜像加速): 连接

1-查看当前使用的仓库

npm config get registry

成功安装:

1- 下载

https://nodejs.org/en/download

各个版本下载:https://nodejs.org/dist/

v16.20.2 针对 centos 7.9 是不需要依赖的。

18.19,20 需要安装 glibc_ , node v18开始 都需要GLIBC_2.27支持

解决方法: node: /lib64/libm.so.6: version `GLIBC_2.27' not found - 丁少华 - 博客园 (cnblogs.com)

我这里下载的是 v20.10.0

https://nodejs.org/dist/v20.10.0/

wget https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.gz

2-安装

解压:

 tar xf node-v20.10.0-linux-x64.tar.gz

3-配置环境变量

vim /etc/profile

export PATH=$PATH:/opt/node-v20.10.0-linux-x64/bin

source /etc/profile

https://blog.csdn.net/qq_42673067/article/details/130401204

{#more-11435}

1-安装Node.js 16

v18.18.2

Node.js 包是通过 NodeSource Node.js Binary Distributions 和 .rpm 提供的。使用以下命令将存储库添加到系统:

curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -

2-安装nodejs

yum install -y nodejs

3-验证

node

退出

.exit

4-安装构建时会用到的原生插件:

yum install -y gcc-c++ make 

5-安装 pm2

PM2是JavaScript运行时Node.js的进程管理器。

npm install -g pm2

如果比较慢,可以设置镜像加速,参考文章开头。

6-Yarn 包管理器

curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
 yum install -y yarn

https://blog.csdn.net/wwj256/article/details/129546899

直接上demo.js:

//得到内置模块,引入NodeJS的内置 http 模块 
var http = require('http');
// 创建服务器,使用createServer方法
var server = http.createServer(function(req,res){
  // req:请求,res: 响应
  // 返回 / 输出
  res.setHeader("Content-Type","text/html;charset=UTF8");
  res.end("hello NodeJs 呀");

});
// port:3000
server.listen(3000);

运行:

 pm2 start demo.js

http://192.168.3.199:3000/

以下方法 安装失败:

https://nodejs.org/en/download

[root@master231 ~]#node 
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
[root@master231 ~]#node -v
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
赞(8)
未经允许不得转载:工具盒子 » nodejs安装(linux)-npm 命令