Amazon Linux tar command not found on AWS cloud

I got development machine running Amazon Linux AMI release 2018.03 with PHP 7.3. I need to untar files so I run in the /var/www/html/images/ directory

tar xvf old-data-file.tar.gz

It said:

bash: tar: command not found

How can I fix this?

Install it using the yum command

sudo yum install tar

Sample outputs:

Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
--> Running transaction check
---> Package tar.x86_64 2:1.26-31.22.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package     Arch           Version                     Repository         Size
================================================================================
Installing:
 tar         x86_64         2:1.26-31.22.amzn1          amzn-main         1.1 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.1 M
Installed size: 2.7 M
Is this ok [y/d/N]: y
Downloading packages:
tar-1.26-31.22.amzn1.x86_64.rpm                            | 1.1 MB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:tar-1.26-31.22.amzn1.x86_64                                1/1 
  Verifying  : 2:tar-1.26-31.22.amzn1.x86_64                                1/1 

Installed:
  tar.x86_64 2:1.26-31.22.amzn1                                                 

Complete!

Now you can use tar on Amazon Linux.


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki