在Centos 7 中,从零搭建Node.js环境(By-Ruicky)

1.jpg

常用装机顺序

  1. 更新本地最新包:yum update -y
  2. 安装常用工具包: yum groupinstall 'Development Tools' -y
  3. 安装Git
    • 安装依赖包:yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel -y
    • yum install curl-devel -y
    • 从GitHub上下载源码:wget https://github.com/git/git/archive/v2.12.2.tar.gz -O git.tar.gz
    • 解压文件:tar -zxf git.tar.gz
    • 切换目录:cd git-*
    • 检查:make configure
    • 加前缀:./configure --prefix=/usr/local
    • 安装:make install
    • 记住密码: git config --global credential.helper cache git config --global credential.helper 'cache --timeout=36000'
  4. 安装Nginx
    • 增加nginx仓库:sudo yum install epel-release -y
    • 安装nginx:sudo yum install nginx -y
    • 启动nginx:sudo systemctl start nginx
    • 开机自启:sudo systemctl enable nginx
  5. 安装Nodejs
    • curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
    • yum -y install nodejs
  6. 安装cnpm(可选,用来加速安装node包的速度)
    • npm install -g cnpm --registry=https://registry.npm.taobao.org
  7. 安装babel
    • npm install -g babel-cli

其他

  1. 报错:libpng12.so.0: cannot open shared object file...
    解决方法:yum install libpng12.x86_64 -y
  2. git clone 项目时候 报错:Unable to find remote helper for 'https'
    解决方法:yum install curl-devel

参考文档

How To Install Git on CentOS 7
How To Install Nginx on CentOS 7
Installing Node.js via package manager
淘宝 NPM 镜像
libpng12.so.0: cannot open shared object file - genymotion
“Unable to find remote helper for ‘https’” during git clone
Caching your GitHub password in Git

-------------------本文结束 感谢您的阅读-------------------
坚持原创技术分享,您的支持将鼓励我继续创作!