4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

特定のバージョンを指定したPythonとAnsibleのインストール手順

Last updated at Posted at 2020-05-15

#概要
この記事は、Linuxに一からPythonとAnsibleをインストールする手順を説明することが目的です。
特定のバージョンを指定してPythonをインストールし、そのPythonと紐づけてAnsibleをインストールしていきます。
#手順
AWSのAmazon EC2を使用します。使用するOSは、『Red Hat Enterprise Linux 8』です。
######①必要なパッケージのインストール

sudo yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel libffi-devel perl-ExtUtils-MakeMaker wget gcc automake autoconf libtool make

標準出力結果で、以下のように「Complete!」が表示されていたら成功です。

Last metadata expiration check: 0:00:06 ago on Thu 14 May 2020 01:21:43 AM UTC.
Dependencies resolved.
========================================================================================================================================================================
 Package                                        Architecture              Version                                   Repository                                     Size
========================================================================================================================================================================
Installing:
 autoconf                                       noarch                    2.69-27.el8                               rhel-8-appstream-rhui-rpms                    710 k
~ 省略 ~
Complete!

######②ディレクトリ移動

cd /usr/local/src/

######③Gitのダウンロード

sudo wget https://www.kernel.org/pub/software/scm/git/git-2.26.2.tar.gz

以下のような標準出力結果であれば、Gitのダウンロードは成功です。

--2020-05-14 02:40:01--  https://www.kernel.org/pub/software/scm/git/git-2.26.2.tar.gz
Resolving www.kernel.org (www.kernel.org)... 147.75.46.191, 2604:1380:4080:c00::1
Connecting to www.kernel.org (www.kernel.org)|147.75.46.191|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.26.2.tar.gz [following]
--2020-05-14 02:40:01--  https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.26.2.tar.gz
Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)... 147.75.95.133, 2604:1380:3000:1500::1
Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|147.75.95.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9282064 (8.9M) [application/x-gzip]
Saving to: ‘git-2.26.2.tar.gz’

git-2.26.2.tar.gz                         100%[=====================================================================================>]   8.85M  10.9MB/s    in 0.8s

2020-05-14 02:40:02 (10.9 MB/s) - ‘git-2.26.2.tar.gz’ saved [9282064/9282064]

######④解凍

sudo tar xzvf git-2.26.2.tar.gz

以下のように、標準出力結果に展開されたディレクトリやファイルが表示されていたら、解凍は成功です。

git-2.26.2/
git-2.26.2/.cirrus.yml
git-2.26.2/.clang-format
git-2.26.2/.editorconfig
git-2.26.2/.gitattributes
git-2.26.2/.github/
git-2.26.2/.github/CONTRIBUTING.md
git-2.26.2/.github/PULL_REQUEST_TEMPLATE.md
~ 省略 ~

######⑤ディレクトリ移動

cd git-2.26.2

######⑥コンパイル

sudo make prefix=/usr/local all

以下のような表示が標準出力結果に続けば、コンパイルは成功です。

GIT_VERSION = 2.26.2
    * new build flags
    CC fuzz-commit-graph.o
    CC fuzz-pack-headers.o
    CC fuzz-pack-idx.o
    CC credential-store.o
    * new link flags
    CC common-main.o
~ 省略 ~

######⑦コンパイルしたものをインストール

sudo make prefix=/usr/local install

以下のような表示が標準出力結果に続けば、コンパイルしたもののインストールは成功です。

    SUBDIR git-gui
    SUBDIR gitk-git
    SUBDIR templates
install -d -m 755 '/usr/local/bin'
install -d -m 755 '/usr/local/libexec/git-core'
install   git-credential-store git-daemon git-fast-import git-http-backend git-imap-send git-sh-i18n--envsubst git-shell git-remote-testsvn git-http-fetch git-http-push git-credential-cache git-credential-cache--daemon git-remote-http git-remote-https git-remote-ftp git-remote-ftps git-bisect git-difftool--helper git-filter-branch git-merge-octopus git-merge-one-file git-merge-resolve git-mergetool git-quiltimport git-legacy-stash git-request-pull git-submodule git-web--browse git-add--interactive git-archimport git-cvsexportcommit git-cvsimport git-cvsserver git-send-email git-svn git-p4 git-instaweb '/usr/local/libexec/git-core'
install -m 644  git-mergetool--lib git-parse-remote git-rebase--preserve-merges git-sh-setup git-sh-i18n '/usr/local/libexec/git-core'
install git git-upload-pack git-receive-pack git-upload-archive git-shell git-cvsserver '/usr/local/bin'
~ 省略 ~

######⑧/etc/profile 内の設定を反映

source /etc/profile

######⑨リポジトリの複製

git clone https://github.com/pyenv/pyenv.git ~/.pyenv

以下のような標準出力結果であれば、リポジトリの複製は成功です。

Cloning into '/home/ec2-user/.pyenv'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 18005 (delta 0), reused 2 (delta 0), pack-reused 17999
Receiving objects: 100% (18005/18005), 3.57 MiB | 2.21 MiB/s, done.
Resolving deltas: 100% (12255/12255), done.

######⑩~/.bash_profile の編集

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

######⑪再起動
######⑫Pythonインストール(特定のバージョン指定)

pyenv install 3.8.2

以下のような標準出力結果であれば、Pythonのインストールは成功です。

Downloading Python-3.8.2.tar.xz...
-> https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
Installing Python-3.8.2...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.8.2 to /home/ec2-user/.pyenv/versions/3.8.2

「Installed Python-3.8.2 to /home/ec2-user/.pyenv/versions/3.8.2」が表示されていたら成功です。
######⑬Python環境を特定のバージョンに切り替え

pyenv global 3.8.2

######⑭Ansibleインストール

pip3 install ansible

以下のように、下から3行目の「Successfully installed MarkupSafe-1.1.1 PyYAML-5.3.1 ansible-2.9.9 cffi-1.14.0 cryptography-2.9.2 jinja2-2.11.2 pycparser-2.20 six-1.14.0」が表示されていたら成功です。

Collecting ansible
  Downloading https://files.pythonhosted.org/packages/00/5d/e10b83e0e6056dbd5b4809b451a191395175a57e3175ce04e35d9c5fc2a0/ansible-2.9.9.tar.gz (14.2MB)
     |????????????????????????????????| 14.2MB 14.9MB/s
Collecting jinja2 (from ansible)
  Downloading https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl (125kB)
     |????????????????????????????????| 133kB 56.9MB/s
Collecting PyYAML (from ansible)
  Downloading https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz (269kB)
     |????????????????????????????????| 276kB 58.8MB/s
Collecting cryptography (from ansible)
  Downloading https://files.pythonhosted.org/packages/3c/04/686efee2dcdd25aecf357992e7d9362f443eb182ecd623f882bc9f7a6bba/cryptography-2.9.2-cp35-abi3-manylinux2010_x86_64.whl (2.7MB)
     |????????????????????????????????| 2.7MB 49.3MB/s
Collecting MarkupSafe>=0.23 (from jinja2->ansible)
  Downloading https://files.pythonhosted.org/packages/4b/20/f6d7648c81cb84815d0be935d5c74cd1cc0239e43eadb1a61062d34b6543/MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl
Collecting six>=1.4.1 (from cryptography->ansible)
  Downloading https://files.pythonhosted.org/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
Collecting cffi!=1.11.3,>=1.8 (from cryptography->ansible)
  Downloading https://files.pythonhosted.org/packages/49/de/1ab40dd857172da4accad610c25badfdfc23ec7e1bbcc6f9212cfcb3419d/cffi-1.14.0-cp38-cp38-manylinux1_x86_64.whl (409kB)
     |????????????????????????????????| 409kB 55.1MB/s
Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography->ansible)
  Downloading https://files.pythonhosted.org/packages/ae/e7/d9c3a176ca4b02024debf82342dab36efadfc5776f9c8db077e8f6e71821/pycparser-2.20-py2.py3-none-any.whl (112kB)
     |????????????????????????????????| 112kB 59.4MB/s
Installing collected packages: MarkupSafe, jinja2, PyYAML, six, pycparser, cffi, cryptography, ansible
  Running setup.py install for PyYAML ... done
  Running setup.py install for ansible ... done
Successfully installed MarkupSafe-1.1.1 PyYAML-5.3.1 ansible-2.9.9 cffi-1.14.0 cryptography-2.9.2 jinja2-2.11.2 pycparser-2.20 six-1.14.0
WARNING: You are using pip version 19.2.3, however version 20.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

以上が、特定のバージョンのPythonをインストールした上で、Pythonと紐づけてAnsibleをインストールする手順となります。
また別のバージョンのPythonをインストールし、そのPythonと紐づけてAnsibleをインストールする場合は、⑫~⑭を再度実行してください。

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?