Solve Linux: [Errno 12] Cannot allocate memory problem

created at 09-11-2021 views: 116

1.cause of the problem

Use Linux (CentOS system) to install Java, the command line prompt:

Error downloading packages:

  libXcursor-1.1.15-1.el7.x86_64: [Errno 5] [Errno 12] Cannot allocate memory

  1:xorg-x11-font-utils-7.5-21.el7.x86_64: [Errno 5] [Errno 12] Cannot allocate memory

Cannot allocate memory, indicating that the memory allocation of the Linux server is not enough.

2. Solution

(1) View the basic situation of the server

swap usage:

swapon --show

result

NAME  TYPE SIZE USED PRIO
/swap file 260M 260M   -1

view disk usage:

df -h

result

Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        494M     0  494M   0% /dev
tmpfs           504M     0  504M   0% /dev/shm
tmpfs           504M   58M  447M  12% /run
tmpfs           504M     0  504M   0% /sys/fs/cgroup
/dev/sda2        22G  2.7G   18G  14% /
/dev/sda1       380M  142M  218M  40% /boot
tmpfs           101M     0  101M   0% /run/user/0

(2) Set up a new swap file and add permissions

fallocate -l 1G /swapfile

And add permissions:

chmod 600 /swapfile

result

-rw------- 1 root root 1.0G Oct 26 22:02 /swapfile

(3) Make the newly created swap file effective

mkswap /swapfile
swapon /swapfile

Check the new swap situation:

swapon --show

result:

NAME      TYPE  SIZE USED PRIO
/swap     file  260M 260M   -1
/swapfile file 1024M   0B   -2

(4) Make the operation permanent, otherwise the above operations will not take effect after restarting

cp /etc/fstab /etc/fstab.bak
echo'/swapfile none swap sw 0 0'| tee -a /etc/fstab

(5) After finishing, you can check the overall effect again.

free -h

result:

         total        used        free      shared  buff/cache   available
Mem:           1.0G        736M         94M         50M        176M         74M
Swap:          1.3G        259M        1.0G
created at:09-11-2021
edited at: 09-11-2021: