[LINUX] Installation procedure for Python and Ansible with a specific version


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".

① Installation of required packages
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
 autoconf                                       noarch                    2.69-27.el8                               rhel-8-appstream-rhui-rpms                    710 k
~ Omitted ~
② Move directory
cd /usr/local/src/
③ Download Git
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)..., 2604:1380:4080:c00::1
Connecting to www.kernel.org (www.kernel.org)||: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)..., 2604:1380:3000:1500::1
Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)||: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]

④ Defrost
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.

~ Omitted ~
⑤ Move directory
cd git-2.26.2
⑥ Compile
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 ~
⑦ Install the compiled version
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 ~
⑧ Reflect the settings in / etc / profile
source /etc/profile
⑨ Repository replication
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.
⑩ Edit ~ / .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
⑪ Reboot
⑫ Python installation (specific version specified)
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.

⑬ Switch Python environment to a specific version
pyenv global 3.8.2
⑭ Ansible installation
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

Installation procedure for Python and Ansible with a specific version
Procedure for creating a LineBot made with Python
Python 3.6 installation procedure [for Windows]
Detect objects of a specific color and size with Python
Library for specifying a name server and dig with python
Create a striped illusion with gamma correction for Python3 and openCV3
Batch download images from a specific URL with python Modified version
Python installation and package management with pip
A memo with Python2.7 and Python3 on CentOS
[GCP] Procedure for creating a web application with Cloud Functions (Python + Flask)
Get a ticket for a theme park with python
Building a python environment with virtualenv and direnv
Create a LINE BOT with Minette for Python
Build a python environment with ansible on centos6
Launch a web server with Python and Flask
[2020 version] Development procedure for personal crawlers and precautions
Commands for creating a python3 environment with virtualenv
Procedure for creating a Python quarantine environment (venv environment)
Python3, venv and Ansible
Check version with python
Procedure to load MNIST with python and output to png
I tried pipenv and asdf for Python version control
Building a Docker working environment for R and Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Specific sample code for working with SQLite3 in Python
Benchmark for C, Java and Python with prime factorization
Create a python development environment with vagrant + ansible + fabric
Let's make a simple game with Python 3 and iPhone
Understanding with mathematical formulas and Python LiNGAM (ICA version)
I made a LINE BOT with Python and Heroku
Procedure for building a CDK environment on Windows (Python)
Build a python virtual environment with virtualenv and virtualenvwrapper
Create a Layer for AWS Lambda Python with Docker
Version control of Node, Ruby and Python with anyenv
Automate background removal for the latest portraits in a directory with Python and API
[Building a CI environment in 2 hours] Procedure for building a Python Web server with CircleCI and passing an HTTP communication test
Encryption and decryption with Python
Offline installation procedure for openpyxl
Python CMS Mezzanine installation procedure
Python and hardware-Using RS232C with Python-
CentOS 8 installation procedure (latest version)
Recommendations for django, wagtail ~ Why develop a website with python ~
Associate Python Enum with a function and make it Callable
Create a child account for connect with Stripe in Python
[Python] Create a date and time list for a specified period
Experiment to make a self-catering PDF for Kindle with Python
Let's create a PRML diagram with Python, Numpy and matplotlib.
Python installation and basic grammar
OpenCV3 installation for Python3 @macOS
Environment construction procedure for those who are not familiar with the python version control system
Recursively get the Excel list in a specific folder with python and write it to Excel.
Analyze stocks with python and look for favorable trading phases
Solving with Ruby, Perl, Java and Python AtCoder ATC 002 A
Try to bring up a subwindow with PyQt5 and Python
A sample for drawing points with PIL (Python Imaging Library).
Create a Twitter BOT with the GoogleAppEngine SDK for Python
Python 3 series installation for mac
Make a fortune with Python
Hash with python and escape from a certain minister's egosa
python with pyenv and venv
Get a list of CloudWatch Metrics and a correspondence table for Unit units with Python boto