JQChan / node-practice

0 stars 0 forks source link

阿里云CentOS 7 / Ubuntu 安装Node #5

Open JQChan opened 4 years ago

JQChan commented 4 years ago

https://github.com/nodejs/node/blob/master/BUILDING.md

  1. 下载Node源码

    wget https://nodejs.org/dist/v12.16.3/node-v12.16.3.tar.gz
  2. 解压包,并进入解压的文件夹

    
    tar xvf node-v12.16.3.tar.gz

cd node-v12.16.3


3. 安装`python gcc-c++ gcc make`等库

- gcc and g++ >= 6.3 or newer, or

- GNU Make 3.81 or newer

- Python 2.7

```bash
sudo yum install python gcc-c++ gcc make

// Ubuntu
sudo apt-get install build-essential 
sudo apt-get install gcc 
sudo apt-get install g++
  1. 安装devtoolset-8,会升级gcc https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/
    
    # 1. Install a package with repository for your system:
    # On CentOS, install package centos-release-scl available in CentOS repository:
    $ sudo yum install centos-release-scl

On RHEL, enable RHSCL repository for you system:

$ sudo yum-config-manager --enable rhel-server-rhscl-7-rpms

2. Install the collection:

$ sudo yum install devtoolset-8

3. Start using software collections:

$ scl enable devtoolset-8 bash


5. 编译
```bash
$ ./configure

$ make -j4
  1. 安装

    $ make install
  2. 检查是否安装成功

    
    node -v

npm -v


8. 如果运行`node -v` 报错
```bash
-bash: /usr/bin/node: No such file or directory
  1. 查找一下node安装位置
    
    whereis node

// 输出 node: /usr/local/bin/node

10. 增加软链接:`node`和`npm`到`/usr/bin`
```bash
sudo ln -s /usr/local/bin/node /usr/bin/node

sudo ln -s /usr/local/bin/npm /usr/bin/npm
  1. 再检查nodenpm版本
    
    node -v

npm -v