'BUILD FAILED (Ubuntu 20.04 using ruby-build 20210119)

I'm using rbenv and in Ec2 instance I'm trying to install a ruby different version but when I execute

rbenv install 2.7.2

following errors occur.

Downloading ruby-2.7.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2
Installing ruby-2.7.2...

BUILD FAILED (Ubuntu 20.04 using ruby-build 20210119)

Inspect or clean up the working tree at /tmp/ruby-build.20210217075101.162094.zs1iDJ
Results logged to /tmp/ruby-build.20210217075101.162094.log

Last 10 log lines:
compiling mjit.c
compiling mjit_compile.c
compiling node.c
compiling numeric.c
compiling object.c
compiling pack.c
compiling parse.c
gcc: fatal error: Killed signal terminated program cc1
compilation terminated.
make: *** [Makefile:421: parse.o] Error 1

meanwhile, my system is using the default ruby version

  ubuntu@ip-112-34-9-342:~$ rbenv versions
 * system (set by /home/ubuntu/.rbenv/version)

I don't confirm it is a space issue or something else, space information is listed below.

 ubuntu@ip-112-34-9-342:~$ free
    total        used        free      shared  buff/cache   available
    Mem:         486776      177636       89396         800      219744      287744
    Swap:          0           0           0


Solution 1:[1]

Run the following -

$ sudo apt install gcc make curl libssl-dev zlib1g-dev

You are welcome.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Georg Keferböck