The purpose of this article is to explain the steps to install Python and Ansible from scratch on Linux. Install Python by specifying a specific version, and install Ansible in association with that Python.
Use Amazon EC2 on AWS. The OS used is "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
If "Complete!" Is displayed in the standard output result as shown below, it is successful.
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
~ Omitted ~
Complete!
cd /usr/local/src/
sudo wget https://www.kernel.org/pub/software/scm/git/git-2.26.2.tar.gz
If you see the following standard output results, the Git download is successful.
--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
If the expanded directories and files are displayed in the standard output results as shown below, the extraction is successful.
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
~ Omitted ~
cd git-2.26.2
sudo make prefix=/usr/local all
If the following display follows the standard output result, the compilation is successful.
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
~ Omitted ~
sudo make prefix=/usr/local install
If the following display follows the standard output result, the compiled version has been successfully installed.
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'
~ Omitted ~
source /etc/profile
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
If you see the following standard output, the repository replication is successful.
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.
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
pyenv install 3.8.2
If you see the following standard output, the Python installation is successful.
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
If "Installed Python-3.8.2 to /home/ec2-user/.pyenv/versions/3.8.2" is displayed, it is successful.
pyenv global 3.8.2
pip3 install ansible
As shown below, "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" on the third line from the bottom. If ".0" is displayed, it is successful.
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.
The above is the procedure to install Ansible by linking with Python after installing a specific version of Python. If you want to install another version of Python and install Ansible in association with that Python, execute ⑫ to ⑭ again.
Recommended Posts