9月 192019
 

今天在EC2(Centos 7)上使用nvm 安装node时出现下面错误提示:

# nvm install 8.16.1
Downloading and installing node v8.16.1…
Downloading https://nodejs.org/dist/v8.16.1/node-v8.16.1-linux-x64.tar.xz…
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
xz: (stdin): Cannot allocate memory
tar: Child returned status 1
tar: Error is not recoverable: exiting now
Binary download failed, trying source.
Downloading https://nodejs.org/dist/v8.16.1/node-v8.16.1.tar.xz…
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
xz: (stdin): Cannot allocate memory
tar: Child returned status 1
tar: Error is not recoverable: exiting now
nvm: install v8.16.1 failed!

这台EC2内存只有1G,看来需要配个交换分区。

 

步骤

# 创建一个全0填充的2GB文件。InputFile利用Linux系统的/dev/zero。bs是BlockSize。

sudo dd if=/dev/zero of=/mnt/2GB.swap bs=1M count=2048

 

# 把该文件格式化为Swap文件

sudo mkswap /mnt/2GB.swap

 

# 把该Swap文件挂载为Swap分区

sudo swapon /mnt/2GB.swap

 

# 检查是否成功挂载。Swap那一行现在就不是0了。

$ free -m

total        used        free      shared  buff/cache   available

Mem:            963         677          74          78         211          52

Swap:          2047          84        1963

# 配置fstab,使开机时自动挂载Swap文件为Swap分区

sudo vim /etc/fstab

 

# 在/ect/fstab中添加

/mnt/2GB.swap none swap sw 0 0

 

Sorry, the comment form is closed at this time.