二度忘れた事を三度忘れないようにする

しがないフリーランスIT系エンジニア

CentOS8にHomebrew(Linuxbrew)でAWS CLI環境を導入する

公式のドキュメント通りにすれば特に問題無いのですが、とりあえずメモ。

とりあえず、homebrewをインストールする前に必要なモノをインストール。

$ sudo dnf install -y git
$ sudo dnf groupinstall 'Development Tools'

先に入れなくてもエラーで「これいれろよ!」的なメッセージでるので、特に困ることはないです。ので、サクサクいきます。

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
$ test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
$ test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
$ test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
$ echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
$ brew --version
Homebrew 2.2.17
Homebrew/linuxbrew-core (git revision a4063; last commit 2020-05-28)
Homebrew/homebrew-cask (git revision cef42; last commit 2020-05-28)

$ brew install gcc #homebrewインストール後に推奨されてたので入れた

次にawscliをインストールするのですが、クリーンな状態だとモジュールが無いと怒られました。

$ brew install awscli
~~~
perl
Makefile.PL
INSTALL_BASE=/home/knhk/.linuxbrew/Cellar/openssl@1.1/1.1.1g/libexec

Can't locate ExtUtils/MakeMaker.pm in @INC (you may need to install the ExtUtils::MakeMaker module) (@INC contains: /home/knhk/.linuxbrew/Cellar/openssl@1.1/1.1.1g/libexec/lib/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at Makefile.PL line 8.
BEGIN failed--compilation aborted at Makefile.PL line 8.

READ THIS: https://docs.brew.sh/Troubleshooting

ということでPerlのモジュールが必要なので、rootでいれてやります。

$ sudo dnf install -y perl-ExtUtils-MakeMaker.noarch
$ brew install awscli
$ aws --version
aws-cli/2.0.17 Python/3.8.2 Linux/4.18.0-147.el8.x86_64 botocore/2.0.0dev21

意図せず昨日リリースしたばかりのバージョンが導入できました。

最後に以下のおまじないをしておくと、awsコマンドを打っているときにTabを押すと候補が出るようになります。

$ which aws_bash_completer
/usr/local/bin/aws_bash_completer
$ echo "source /usr/local/bin/aws_bash_completer" >> .bash_profile

なお、CentOS8以外のLinuxでもパッケージマネージャが違う位で、手順な等は大きく変わらないと思います。