VirtualBox+VagrantでCentOS7環境構築し、Python3.6をインストールしてみる

VirtualBoxのインストールと、Vagrantをインストールし、CentOS7を動かしてみましたので、今回は、Python3.6をインストールしてみます。

■Vagrantにログインする

まず、Windows10の検索ボックスで「cmd」と検索して「コマンドプロンプト」を起動します。

起動後、Vagrantへのログインを試みます。

vagrant up

ログインを試みるために、上記のコマンドを入力し、Enterキーを押します。

Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> default: Checking if box ‘centos/7’ version ‘2004.01’ is up to date…
==> default: Clearing any previously set forwarded ports…
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces…
==> default: Preparing network interfaces based on configuration…
default: Adapter 1: nat
==> default: Forwarding ports…
default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM…
==> default: Waiting for machine to boot. This may take a few minutes…
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection reset. Retrying…
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM…
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Rsyncing folder: /cygdrive/c/Users/user/ => /vagrant

Enterキーを押すと、仮想マシン(CentOS7)が起動します。

vagrant ssh

起動後、Vagrantにログインするために、上記のコマンドを入力し、Enterキーを押します。

[vagrant@localhost ~]$

Enterキーを押すと、ログインが成功します。

■CentOS7にリポジトリを追加

ログインした後は、IUS Community Projectを利用してCentOS7にリポジトリを追加します。CentOS7のデフォルトのリポジトリでは、Python3.6が提供されていません。

[vagrant@localhost ~]$ sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm

追加するために、上記のコマンドを入力し、Enterキーを押します。

Loaded plugins: fastestmirror
Cannot open: https://centos7.iuscommunity.org/ius-release.rpm. Skipping.
Error: Nothing to do

Enterキーを押すと、Errorが発生した。原因を調べてみると、iusの最新リンクが変更になったということなので、リンクを変更する。

[vagrant@localhost ~]$ sudo yum install -y https://repo.ius.io/ius-release-el7.rpm

リンクを変更すると上記のコマンドとなり、入力し、Enterキーを押します。

Loaded plugins: fastestmirror
ius-release-el7.rpm | 8.2 kB 00:00:00
Examining /var/tmp/yum-root-NK87DQ/ius-release-el7.rpm: ius-release-2-1.el7.ius.noarch
Marking /var/tmp/yum-root-NK87DQ/ius-release-el7.rpm to be installed
Resolving Dependencies
–> Running transaction check
—> Package ius-release.noarch 0:2-1.el7.ius will be installed
–> Processing Dependency: epel-release = 7 for package: ius-release-2-1.el7.ius.noarch
Loading mirror speeds from cached hostfile
* base: ftp.nara.wide.ad.jp
* extras: ftp.nara.wide.ad.jp
* updates: ftp.nara.wide.ad.jp
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql56-community | 2.5 kB 00:00:00
updates | 2.9 kB 00:00:00
–> Running transaction check
—> Package epel-release.noarch 0:7-11 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================
Installing:
ius-release noarch 2-1.el7.ius /ius-release-el7 4.5 k
Installing for dependencies:
epel-release noarch 7-11 extras 15 k

Transaction Summary
=====================================================================================================================
Install 1 Package (+1 Dependent package)

Total size: 19 k
Total download size: 15 k
Installed size: 29 k
Downloading packages:
epel-release-7-11.noarch.rpm | 15 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-11.noarch 1/2
Installing : ius-release-2-1.el7.ius.noarch 2/2
Verifying : ius-release-2-1.el7.ius.noarch 1/2
Verifying : epel-release-7-11.noarch 2/2

Installed:
ius-release.noarch 0:2-1.el7.ius

Dependency Installed:
epel-release.noarch 0:7-11

Complete!

Enterキーを押すと、インストールが開始され、「Complete!」と表示されます。これでリポジトリの追加ができました。

■Python3.6のインストール

リポジトリの追加後は、Python3.6のインストールを行います。

[vagrant@localhost ~]$ sudo yum install python36u python36u-libs python36u-devel python36u-pip

インストールを行うためには、上記のコマンドを入力し、Enterキーを押します。

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.7 kB 00:00:00
* base: ftp.nara.wide.ad.jp
* epel: nrt.edge.kernel.org
* extras: ftp.nara.wide.ad.jp
* updates: ftp.nara.wide.ad.jp
epel | 4.7 kB 00:00:00
ius | 1.3 kB 00:00:00
(1/4): epel/x86_64/group_gz | 95 kB 00:00:01
(2/4): ius/x86_64/primary | 171 kB 00:00:01
(3/4): epel/x86_64/updateinfo | 1.0 MB 00:00:02
(4/4): epel/x86_64/primary_db | 6.9 MB 00:00:05
ius 931/931
Package python36u is obsoleted by python3, trying to install python3-3.6.8-13.el7.x86_64 instead
Package python36u-libs is obsoleted by python3-libs, trying to install python3-libs-3.6.8-13.el7.x86_64 instead
Package python36-devel is obsoleted by python3-devel, trying to install python3-devel-3.6.8-13.el7.x86_64 instead
Package python36u-pip is obsoleted by python3-pip, trying to install python3-pip-9.0.3-7.el7_7.noarch instead
Resolving Dependencies
–> Running transaction check
—> Package python3.x86_64 0:3.6.8-13.el7 will be installed
–> Processing Dependency: python3-setuptools for package: python3-3.6.8-13.el7.x86_64
—> Package python3-devel.x86_64 0:3.6.8-13.el7 will be installed
–> Processing Dependency: redhat-rpm-config for package: python3-devel-3.6.8-13.el7.x86_64
–> Processing Dependency: python3-rpm-macros for package: python3-devel-3.6.8-13.el7.x86_64
–> Processing Dependency: python3-rpm-generators for package: python3-devel-3.6.8-13.el7.x86_64
–> Processing Dependency: python-rpm-macros for package: python3-devel-3.6.8-13.el7.x86_64
—> Package python3-libs.x86_64 0:3.6.8-13.el7 will be installed
—> Package python3-pip.noarch 0:9.0.3-7.el7_7 will be installed
–> Running transaction check
—> Package python-rpm-macros.noarch 0:3-32.el7 will be installed
–> Processing Dependency: python-srpm-macros for package: python-rpm-macros-3-32.el7.noarch
—> Package python3-rpm-generators.noarch 0:6-2.el7 will be installed
—> Package python3-rpm-macros.noarch 0:3-32.el7 will be installed
—> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed
—> Package redhat-rpm-config.noarch 0:9.1.0-88.el7.centos will be installed
–> Processing Dependency: dwz >= 0.4 for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch
–> Processing Dependency: zip for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch
–> Processing Dependency: perl-srpm-macros for package: redhat-rpm-config-9.1.0-88.el7.centos.noarch
–> Running transaction check
—> Package dwz.x86_64 0:0.11-3.el7 will be installed
—> Package perl-srpm-macros.noarch 0:1-8.el7 will be installed
—> Package python-srpm-macros.noarch 0:3-32.el7 will be installed
—> Package zip.x86_64 0:3.0-11.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================
Installing:
python3 x86_64 3.6.8-13.el7 base 69 k
python3-devel x86_64 3.6.8-13.el7 base 215 k
python3-libs x86_64 3.6.8-13.el7 base 7.0 M
python3-pip noarch 9.0.3-7.el7_7 updates 1.8 M
Installing for dependencies:
dwz x86_64 0.11-3.el7 base 99 k
perl-srpm-macros noarch 1-8.el7 base 4.6 k
python-rpm-macros noarch 3-32.el7 base 8.8 k
python-srpm-macros noarch 3-32.el7 base 8.4 k
python3-rpm-generators noarch 6-2.el7 base 20 k
python3-rpm-macros noarch 3-32.el7 base 7.7 k
python3-setuptools noarch 39.2.0-10.el7 base 629 k
redhat-rpm-config noarch 9.1.0-88.el7.centos base 81 k
zip x86_64 3.0-11.el7 base 260 k

Transaction Summary
=====================================================================================================================
Install 4 Packages (+9 Dependent packages)

Total download size: 10 M
Installed size: 50 M
Is this ok [y/d/N]: y
Downloading packages:
(1/13): python3-3.6.8-13.el7.x86_64.rpm | 69 kB 00:00:00
(2/13): perl-srpm-macros-1-8.el7.noarch.rpm | 4.6 kB 00:00:01
(3/13): python-srpm-macros-3-32.el7.noarch.rpm | 8.4 kB 00:00:00
(4/13): dwz-0.11-3.el7.x86_64.rpm | 99 kB 00:00:00
(5/13): python3-rpm-generators-6-2.el7.noarch.rpm | 20 kB 00:00:00
(6/13): python-rpm-macros-3-32.el7.noarch.rpm | 8.8 kB 00:00:01
(7/13): python3-rpm-macros-3-32.el7.noarch.rpm | 7.7 kB 00:00:00
(8/13): python3-setuptools-39.2.0-10.el7.noarch.rpm | 629 kB 00:00:00
(9/13): zip-3.0-11.el7.x86_64.rpm | 260 kB 00:00:00
(10/13): redhat-rpm-config-9.1.0-88.el7.centos.noarch.rpm | 81 kB 00:00:00
(11/13): python3-devel-3.6.8-13.el7.x86_64.rpm | 215 kB 00:00:01
(12/13): python3-pip-9.0.3-7.el7_7.noarch.rpm | 1.8 MB 00:00:01
(13/13): python3-libs-3.6.8-13.el7.x86_64.rpm | 7.0 MB 00:00:03
———————————————————————————————————————
Total 2.1 MB/s | 10 MB 00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python3-pip-9.0.3-7.el7_7.noarch 1/13
Installing : python3-setuptools-39.2.0-10.el7.noarch 2/13
Installing : python3-libs-3.6.8-13.el7.x86_64 3/13
Installing : python3-3.6.8-13.el7.x86_64 4/13
Installing : python-srpm-macros-3-32.el7.noarch 5/13
Installing : python-rpm-macros-3-32.el7.noarch 6/13
Installing : python3-rpm-generators-6-2.el7.noarch 7/13
Installing : dwz-0.11-3.el7.x86_64 8/13
Installing : python3-rpm-macros-3-32.el7.noarch 9/13
Installing : zip-3.0-11.el7.x86_64 10/13
Installing : perl-srpm-macros-1-8.el7.noarch 11/13
Installing : redhat-rpm-config-9.1.0-88.el7.centos.noarch 12/13
Installing : python3-devel-3.6.8-13.el7.x86_64 13/13
Verifying : python3-rpm-generators-6-2.el7.noarch 1/13
Verifying : python3-devel-3.6.8-13.el7.x86_64 2/13
Verifying : python3-3.6.8-13.el7.x86_64 3/13
Verifying : perl-srpm-macros-1-8.el7.noarch 4/13
Verifying : zip-3.0-11.el7.x86_64 5/13
Verifying : python3-pip-9.0.3-7.el7_7.noarch 6/13
Verifying : python3-rpm-macros-3-32.el7.noarch 7/13
Verifying : python3-setuptools-39.2.0-10.el7.noarch 8/13
Verifying : python-rpm-macros-3-32.el7.noarch 9/13
Verifying : python3-libs-3.6.8-13.el7.x86_64 10/13
Verifying : dwz-0.11-3.el7.x86_64 11/13
Verifying : python-srpm-macros-3-32.el7.noarch 12/13
Verifying : redhat-rpm-config-9.1.0-88.el7.centos.noarch 13/13

Installed:
python3.x86_64 0:3.6.8-13.el7 python3-devel.x86_64 0:3.6.8-13.el7 python3-libs.x86_64 0:3.6.8-13.el7
python3-pip.noarch 0:9.0.3-7.el7_7

Dependency Installed:
dwz.x86_64 0:0.11-3.el7 perl-srpm-macros.noarch 0:1-8.el7
python-rpm-macros.noarch 0:3-32.el7 python-srpm-macros.noarch 0:3-32.el7
python3-rpm-generators.noarch 0:6-2.el7 python3-rpm-macros.noarch 0:3-32.el7
python3-setuptools.noarch 0:39.2.0-10.el7 redhat-rpm-config.noarch 0:9.1.0-88.el7.centos
zip.x86_64 0:3.0-11.el7

Complete!

Enterキーを押すと、インストールが開始されます。途中で「Is this ok」と質問されますので「y」と入力し、Enterキーを押すと、インストールが進み、「Complete!」と表示されます。これで、インストールは完了となります。

■Python3.6を実行する

インストールが完了しましたので、Python3.6を実行してみます。

[vagrant@localhost ~]$ python3.6

実行するためには、上記のコマンドを入力し、Enterキーを押します。

Python 3.6.8 (default, Apr 2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

Enterキーを押すと、Python3.6の対話モードになります。対話モードになりましたので、print関数を使ってテストしてみます。

>>> print(‘こんにちは’)
こんにちは
>>>

テストしてみると、print関数で設定した文字列の値を出力することができました。

コメント

タイトルとURLをコピーしました