How do I install a software package (known as a topic) from the amazon-linux-extras repository on an Amazon Elastic Compute Cloud (Amazon EC2) instance that's running Amazon Linux 2?
Short description
To install a software package from the Extras Library, first confirm that the amazon-linux-extras repository is installed on your instance. Then, list the available software packages, enable the one you're looking for, and then install the package using yum.
Note: This resolution is for Amazon Linux 2. These steps don't apply to Amazon Linux 1 2018.03.
Resolution
1. Connect to your EC2 Linux instance using SSH.
2. Use the which command to confirm that the amazon-linux-extras package is installed:
$ which amazon-linux-extras
/usr/bin/amazon-linux-extras
If the amazon-linux-extras package isn't installed, use yum to install it:
$ sudo yum install -y amazon-linux-extras
3. List the available topics.
Note: The repository is updated regularly, so the topics and versions that you see might differ from the following list.
$ amazon-linux-extras
0 ansible2 available [ =2.4.2 =2.4.6 ]
2 httpd_modules available [ =1.0 ]
3 memcached1.5 available [ =1.5.1 ]
4 nginx1.12 available [ =1.12.2 ]
5 postgresql9.6 available [ =9.6.6 =9.6.8 ]
6 postgresql10 available [ =10 ]
8 redis4.0 available [ =4.0.5 =4.0.10 ]
9 R3.4 available [ =3.4.3 ]
10 rust1 available [ =1.22.1 =1.26.0 =1.26.1 =1.27.2 =1.31.0 ]
11 vim available [ =8.0 ]
13 ruby2.4 available [ =2.4.2 =2.4.4 ]
15 php7.2 available [ =7.2.0 =7.2.4 =7.2.5 =7.2.8 =7.2.11 =7.2.13 =7.2.14 =7.2.16 ]
16 php7.1 available [ =7.1.22 =7.1.25 =7.1.27 ]
17 lamp-mariadb10.2-php7.2 available [ =10.2.10_7.2.0 =10.2.10_7.2.4 =10.2.10_7.2.5 =10.2.10_7.2.8 =10.2.10_7.2.11 =10.2.10_7.2.13 =10.2.10_7.2.14 =10.2.10_7.2.16 ]
18 libreoffice available [ =5.0.6.2_15 =5.3.6.1 ]
19 gimp available [ =2.8.22 ]
20 docker=latest available [ =17.12.1 =18.03.1 =18.06.1 ]
21 mate-desktop1.x available [ =1.19.0 =1.20.0 ]
22 GraphicsMagick1.3 available [ =1.3.29 ]
23 tomcat8.5 available [ =8.5.31 =8.5.32 =8.5.38 ]
24 epel available [ =7.11 ]
25 testing available [ =1.0 ]
26 ecs available [ =stable ]
27 corretto8 available [ =1.8.0_192 =1.8.0_202 ]
28 firecracker available [ =0.11 ]
29 golang1.11 available [ =1.11.3 ]
30 squid4 available [ =4 ]
31 php7.3 available [ =7.3.2 =7.3.3 ]
32 lustre2.10 available [ =2.10.5 ]
33 java-openjdk11 available [ =11 ]
34 lynis available [ =stable ]
4. Enable the desired topic. The output shows the commands required for installation. For example, to enable the PHP 7.2 topic, use the following command:
$ sudo amazon-linux-extras enable php7.2
0 ansible2 available [ =2.4.2 =2.4.6 ]
2 httpd_modules available [ =1.0 ]
3 memcached1.5 available [ =1.5.1 ]
4 nginx1.12 available [ =1.12.2 ]
5 postgresql9.6 available [ =9.6.6 =9.6.8 ]
6 postgresql10 available [ =10 ]
8 redis4.0 available [ =4.0.5 =4.0.10 ]
9 R3.4 available [ =3.4.3 ]
10 rust1 available [ =1.22.1 =1.26.0 =1.26.1 =1.27.2 =1.31.0 ]
11 vim available [ =8.0 ]
13 ruby2.4 available [ =2.4.2 =2.4.4 ]
15 php7.2=latest enabled [ =7.2.0 =7.2.4 =7.2.5 =7.2.8 =7.2.11 =7.2.13 =7.2.14 =7.2.16 ]
_ php7.1 available [ =7.1.22 =7.1.25 =7.1.27 ]
17 lamp-mariadb10.2-php7.2 available [ =10.2.10_7.2.0 =10.2.10_7.2.4 =10.2.10_7.2.5 =10.2.10_7.2.8 =10.2.10_7.2.11 =10.2.10_7.2.13 =10.2.10_7.2.14 =10.2.10_7.2.16 ]
18 libreoffice available [ =5.0.6.2_15 =5.3.6.1 ]
19 gimp available [ =2.8.22 ]
20 docker=latest available [ =17.12.1 =18.03.1 =18.06.1 ]
21 mate-desktop1.x available [ =1.19.0 =1.20.0 ]
22 GraphicsMagick1.3 available [ =1.3.29 ]
23 tomcat8.5 available [ =8.5.31 =8.5.32 =8.5.38 ]
24 epel available [ =7.11 ]
25 testing available [ =1.0 ]
26 ecs available [ =stable ]
27 corretto8 available [ =1.8.0_192 =1.8.0_202 ]
28 firecracker available [ =0.11 ]
29 golang1.11 available [ =1.11.3 ]
30 squid4 available [ =4 ]
_ php7.3 available [ =7.3.2 =7.3.3 ]
32 lustre2.10 available [ =2.10.5 ]
33 java-openjdk11 available [ =11 ]
34 lynis available [ =stable ]
Now you can install:
# yum clean metadata
# yum install php-cli php-pdo php-fpm php-json php-mysqlnd
5. Install the topic using yum. For example, to install the PHP 7.2 topic, use the following command:
$ sudo yum clean metadata && sudo yum install php-cli php-pdo php-fpm php-json php-mysqlnd
6. Use the following commands to verify the installation and confirm the software version:
$ yum list installed php-cli php-pdo php-fpm php-json php-mysqlnd
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Installed Packages
php-cli.x86_64 7.2.16-1.amzn2.0.1 @amzn2extra-php7.2
php-fpm.x86_64 7.2.16-1.amzn2.0.1 @amzn2extra-php7.2
php-json.x86_64 7.2.16-1.amzn2.0.1 @amzn2extra-php7.2
php-mysqlnd.x86_64 7.2.16-1.amzn2.0.1 @amzn2extra-php7.2
php-pdo.x86_64 7.2.16-1.amzn2.0.1 @amzn2extra-php7.2
$ which php
/usr/bin/php
$ php --version
PHP 7.2.16 (cli) (built: Apr 3 2019 18:39:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Related information
Amazon Linux 2