LoginSignup
3
4

More than 3 years have passed since last update.

MACにAWSCLI1.xをインストールするまで

Last updated at Posted at 2019-05-07

まっさらなMacPCにAWSCLIをインストールするまでの構築手順を記載します。

2020/11/10 更新

現在ではpythonが内包されたAWS-CLI2が推奨されています。
インストール手順については以下を参照ください。

参照:macOS での AWS CLI バージョン 2 のインストール、更新、アンインストール
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/install-cliv2-mac.html

環境

macOS Mojave 10.14.4

インストールするもの

  • Homebrew@2.2.9
  • pyenv@1.2.11-11-g7dd50144
  • pip@19.2.3
  • aws-cli@1.16.150

Homebrewのインストール

参考: Homebrew のインストールと基本的な使い方

XcodeのCommand Line Toolsが必要です。事前にxcodeをインストールしてください。

$ xcode-select --install
xcode-select: note: install requested for command line developer tools

$ xcode-select -v
xcode-select version 2354.

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

$ brew --version
Homebrew 2.2.9

pyenvのインストール

バージョン切り替えをしやすくするためにpyenvを利用します。
参考: pyenvのインストール、使い方、pythonのバージョン切り替えできない時の対処法

$ git clone git://github.com/yyuu/pyenv.git ~/.pyenv
Cloning into '/Users/t-yasukawa/.pyenv'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 17306 (delta 0), reused 2 (delta 0), pack-reused 17300
Receiving objects: 100% (17306/17306), 3.34 MiB | 2.39 MiB/s, done.
Resolving deltas: 100% (11791/11791), done.
Checking out files: 100% (645/645), done.

pyenvのパスを設定します。

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

MacOS Mojaveのpyenvでpythonのインストールに失敗する時の対応

これをやらないとmojaveではpythonのインストールに失敗します。
参考: [MacOS Mojave]pyenvでpythonのインストールがzlibエラーで失敗した時の対応

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Password:
installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path /
installer: The install was successful.

python3.7のインストール

$ pyenv install 3.7.3
Downloading openssl-1.1.0j.tar.gz...
-> https://www.openssl.org/source/openssl-1.1.0j.tar.gz
Installing openssl-1.1.0j...
Installed openssl-1.1.0j to /Users/t-yasukawa/.pyenv/versions/3.7.3

Downloading readline-8.0.tar.gz...
-> https://ftpmirror.gnu.org/readline/readline-8.0.tar.gz
Installing readline-8.0...
Installed readline-8.0 to /Users/t-yasukawa/.pyenv/versions/3.7.3

Downloading Python-3.7.3.tar.xz...
-> https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
Installing Python-3.7.3...
Installed Python-3.7.3 to /Users/t-yasukawa/.pyenv/versions/3.7.3

pythonのバージョン確認

プリインストールで2系のpythonが既に入っていると思います。

$ python --version
Python 2.7.10

pyenvに新しくインストールしたversionがあるか確認します。

$ pyenv versions
* system (set by /Users/t-yasukawa/.pyenv/version)
  3.7.3

3.7.3を適用します。

$ pyenv global 3.7.3
$ python --version
Python 3.7.3

pipのインストール

pyenvでインストールされたバージョンであればpipが既に使える状態になっています。

$ pip -V
pip 19.0.3 from /Users/t-yasukawa/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pip (python 3.7)

ついでにpipのアップグレードを行います。

$ pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 6.5MB/s 
Installing collected packages: pip
  Found existing installation: pip 19.0.3
    Uninstalling pip-19.0.3:
      Successfully uninstalled pip-19.0.3
Successfully installed pip-19.1.1

更新できました。

$ pip -V
pip 19.1.1 from /Users/t-yasukawa/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pip (python 3.7)

AWSCLIのインストール

やっとAWSCLIをインストールできるようになりました。

$ pip install awscli --upgrade --user

パスを追加します。

$ echo 'export PATH="~/.local/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile

awsのバージョンを確認します。

$ aws --version
aws-cli/1.16.153 Python/3.7.3 Darwin/18.5.0 botocore/1.12.143
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4