当記事では、Linux系OSにaws cliをインストールする方法について記載します。
目次
更新履歴
2021/11/08 公開しました。
2025/09/25 手順を追記しました。
概要
当記事ではオンプレミスのLinux系OS若しくはAmazonlinux以外のEC2上のLinux系OSにてaws cliを実行するための方法を記載しています。
前提
- 当記事ではAWS上に用意したRHEL8系での手順となります。
- インストールするaws cliは最新バージョンのものとなります。
- 当記事は下記リンクの記載内容を参考に作成しています。
https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html
インストール方法について
- 用意したRHEL8系にてaws cliが存在していない事及びOSバージョンを確認します。
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ aws --version -bash: aws: command not found [ec2-user@ip-xxx-xxx-xxx-xxx ~]$ cat /etc/os-release NAME="Red Hat Enterprise Linux" VERSION="8.4 (Ootpa)" ID="rhel" ID_LIKE="fedora" VERSION_ID="8.4" PLATFORM_ID="platform:el8" PRETTY_NAME="Red Hat Enterprise Linux 8.4 (Ootpa)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:redhat:enterprise_linux:8.4:GA" HOME_URL="https://www.redhat.com/" DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/8/" BUG_REPORT_URL="https://bugzilla.redhat.com/" REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8" REDHAT_BUGZILLA_PRODUCT_VERSION=8.4 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="8.4" [ec2-user@ip-xxx-xxx-xxx-xxx ~]$
- aws cliをインストールします。unzipがインストールされていない場合、事前にインストールしてください。
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 42.4M 100 42.4M 0 0 55.8M 0 --:--:-- --:--:-- --:--:-- 55.8Mm
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ unzip awscliv2.zip
Archive: awscliv2.zip
creating: aws/
creating: aws/dist/
inflating: aws/install
inflating: aws/THIRD_PARTY_LICENSES
inflating: aws/README.md
~省略~
inflating: aws/dist/cryptography-3.3.2-py3.8.egg-info/LICENSE.APACHE
inflating: aws/dist/cryptography-3.3.2-py3.8.egg-info/LICENSE
inflating: aws/dist/cryptography-3.3.2-py3.8.egg-info/METADATA
creating: aws/dist/zlib/cpython-38-x86_64-linux-gnu/
inflating: aws/dist/zlib/cpython-38-x86_64-linux-gnu/soib.cpython-38-x86_64-linux-gnu.so
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo ./aws/install
You can now run: /usr/local/bin/aws --version
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$
- バージョンを確認します。
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ aws --version aws-cli/2.2.43 Python/3.8.8 Linux/4.18.0-305.el8.x86_64 exe/x86_64.rhel.8 prompt/off [ec2-user@ip-xxx-xxx-xxx-xxx ~]$
- sudoにてコマンドが実行できることを確認します。
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo aws --version aws-cli/2.2.43 Python/3.8.8 Linux/4.18.0-305.el8.x86_64 exe/x86_64.rhel.8 prompt/off [ec2-user@ip-xxx-xxx-xxx-xxx ~]$
- sudoにてコマンドが実行できない場合、/etc/sudoersのsecure_pathにawsコマンドのパスを追記してください。
変更前
[root@ip-xxx-xxx-xxx-xxx ~]# grep secure_path /etc/sudoers Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin [root@ip-xxx-xxx-xxx-xxx ~]#
変更後
[root@ip-xxx-xxx-xxx-xxx ~]# which aws /usr/local/bin/aws [root@ip-xxx-xxx-xxx-xxx ~]# grep secure_path /etc/sudoers Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin [root@ip-xxx-xxx-xxx-xxx ~]#
以上で、Linux系OSにaws cliバージョン2をインストールする方法についての説明は終了となります。
記載されている会社名、システム名、製品名は一般に各社の登録商標または商標です。
当社製品以外のサードパーティ製品の設定内容につきましては、弊社サポート対象外となります。


















