Ubuntu(WSL)にbrew / tfenvをインストール
概要
- WSL(Windows Subsystem for Linux)+ Ubuntuの環境に、brew / tfenv をインストールする手順をまとめます。brew は、tfenv をインストールするために導入しています。
brew インストール手順
パッケージのアップデート
- 事前作業として、Ubuntuにインストールされているパッケージのアップデートを行います。apt-get updateでパッケージリストを更新します。続けて、apt-get upgradeでインストールされているパッケージのアップデートを行います。ログは省略します。
niikawa@niikawa1:~$ sudo apt update && sudo apt upgrade
requiredパッケージのインストール
- brew に必要な build-essential およびその他のパッケージをインストールします。
niikawa@niikawa1:~$ sudo apt-get install build-essential curl file git
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version (12.4ubuntu1).
build-essential set to manually installed.
curl is already the newest version (7.58.0-2ubuntu3.13).
file is already the newest version (1:5.32-2ubuntu0.4).
git is already the newest version (1:2.17.1-1ubuntu0.8).
The following packages were automatically installed and are no longer required:
fonts-lato javascript-common libfreetype6 libjs-jquery ruby-did-you-mean ruby-minitest ruby-net-telnet
ruby-power-assert rubygems-integration
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
linuxbrew のインストール
- apt installコマンドで、linuxbrew-wrapper(Homebrew on Linux)をインストールします。
niikawa@niikawa1:~$ sudo apt install linuxbrew-wrapper
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libfreetype6
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libpython-stdlib libpython2.7-minimal libpython2.7-stdlib libruby2.5 python python-minimal python-pkg-resources
python-setuptools python2.7 python2.7-minimal rake ruby ruby-test-unit ruby2.5
Suggested packages:
python-doc python-tk python-setuptools-doc python2.7-doc binfmt-support ri ruby-dev
The following NEW packages will be installed:
libpython-stdlib libpython2.7-minimal libpython2.7-stdlib libruby2.5 linuxbrew-wrapper python python-minimal
python-pkg-resources python-setuptools python2.7 python2.7-minimal rake ruby ruby-test-unit ruby2.5
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
Need to get 7558 kB/7670 kB of archives.
After this operation, 33.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
** 省略 **
Setting up libpython2.7-stdlib:amd64 (2.7.17-1~18.04ubuntu1.6) ...
Setting up python2.7 (2.7.17-1~18.04ubuntu1.6) ...
Setting up libpython-stdlib:amd64 (2.7.15~rc1-1) ...
Setting up python (2.7.15~rc1-1) ...
Setting up python-pkg-resources (39.0.1-2) ...
Setting up python-setuptools (39.0.1-2) ...
Setting up rake (12.3.1-1ubuntu0.1) ...
Setting up ruby-test-unit (3.2.5-1) ...
Setting up libruby2.5:amd64 (2.5.1-1ubuntu1.9) ...
Setting up ruby2.5 (2.5.1-1ubuntu1.9) ...
Setting up ruby (1:2.5.1) ...
Setting up linuxbrew-wrapper (20170516-2) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for mime-support (3.60ubuntu1) ...
- 次に、Homebrew をトラブルシューティングするための brew doctor コマンドを実行します。このコマンドでは、brew を実行するために不足しているセットアップが行われます。
niikawa@niikawa1:~$ brew doctor
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:29: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:30: warning: constant Gem::ConfigMap is deprecated
/usr/lib/linuxbrew-wrapper/install:203: warning: Insecure world writable dir /home/niikawa/.local/bin in PATH, mode 040777
==> This script will install:
/home/linuxbrew/.linuxbrew/bin/brew
/home/linuxbrew/.linuxbrew/share/doc/homebrew
/home/linuxbrew/.linuxbrew/share/man/man1/brew.1
/home/linuxbrew/.linuxbrew/share/zsh/site-functions/_brew
/home/linuxbrew/.linuxbrew/etc/bash_completion.d/brew
/home/niikawa/.cache/Homebrew/
/home/linuxbrew/.linuxbrew/Homebrew
==> The following new directories will be created:
/home/linuxbrew/.linuxbrew/Cellar
/home/linuxbrew/.linuxbrew/bin
/home/linuxbrew/.linuxbrew/etc
/home/linuxbrew/.linuxbrew/include
/home/linuxbrew/.linuxbrew/lib
/home/linuxbrew/.linuxbrew/opt
/home/linuxbrew/.linuxbrew/sbin
/home/linuxbrew/.linuxbrew/share
/home/linuxbrew/.linuxbrew/share/zsh
/home/linuxbrew/.linuxbrew/share/zsh/site-functions
/home/linuxbrew/.linuxbrew/var
/home/linuxbrew/.linuxbrew/Homebrew
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /home/linuxbrew/.linuxbrew
==> /usr/bin/sudo /bin/chown niikawa:niikawa /home/linuxbrew/.linuxbrew
==> /usr/bin/sudo /bin/mkdir -p /home/linuxbrew/.linuxbrew/Cellar /home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/etc /home/linuxbrew/.linuxbrew/include /home/linuxbrew/.linuxbrew/lib /home/linuxbrew/.linuxbrew/opt /home/linuxbrew/.linuxbrew/sbin /home/linuxbrew/.linuxbrew/share /home/linuxbrew/.linuxbrew/share/zsh /home/linuxbrew/.linuxbrew/share/zsh/site-functions /home/linuxbrew/.linuxbrew/var /home/linuxbrew/.linuxbrew/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /home/linuxbrew/.linuxbrew/Cellar /home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/etc /home/linuxbrew/.linuxbrew/include /home/linuxbrew/.linuxbrew/lib /home/linuxbrew/.linuxbrew/opt /home/linuxbrew/.linuxbrew/sbin /home/linuxbrew/.linuxbrew/share /home/linuxbrew/.linuxbrew/share/zsh /home/linuxbrew/.linuxbrew/share/zsh/site-functions /home/linuxbrew/.linuxbrew/var /home/linuxbrew/.linuxbrew/Homebrew
==> /usr/bin/sudo /bin/chmod 755 /home/linuxbrew/.linuxbrew/share/zsh /home/linuxbrew/.linuxbrew/share/zsh/site-functions
==> /usr/bin/sudo /bin/chown niikawa /home/linuxbrew/.linuxbrew/Cellar /home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/etc /home/linuxbrew/.linuxbrew/include /home/linuxbrew/.linuxbrew/lib /home/linuxbrew/.linuxbrew/opt /home/linuxbrew/.linuxbrew/sbin /home/linuxbrew/.linuxbrew/share /home/linuxbrew/.linuxbrew/share/zsh /home/linuxbrew/.linuxbrew/share/zsh/site-functions /home/linuxbrew/.linuxbrew/var /home/linuxbrew/.linuxbrew/Homebrew
==> /usr/bin/sudo /bin/chgrp niikawa /home/linuxbrew/.linuxbrew/Cellar /home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/etc /home/linuxbrew/.linuxbrew/include /home/linuxbrew/.linuxbrew/lib /home/linuxbrew/.linuxbrew/opt /home/linuxbrew/.linuxbrew/sbin /home/linuxbrew/.linuxbrew/share /home/linuxbrew/.linuxbrew/share/zsh /home/linuxbrew/.linuxbrew/share/zsh/site-functions /home/linuxbrew/.linuxbrew/var /home/linuxbrew/.linuxbrew/Homebrew
==> /usr/bin/sudo /bin/mkdir -p /home/niikawa/.cache/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /home/niikawa/.cache/Homebrew
==> /usr/bin/sudo /bin/chown niikawa /home/niikawa/.cache/Homebrew
==> /usr/bin/sudo /bin/chgrp niikawa /home/niikawa/.cache/Homebrew
==> Downloading and installing Linuxbrew...
** 省略 **
Cloning into '/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1191125, done.
remote: Counting objects: 100% (3687/3687), done.
remote: Compressing objects: 100% (1424/1424), done.
remote: Total 1191125 (delta 2428), reused 3383 (delta 2263), pack-reused 1187438
Receiving objects: 100% (1191125/1191125), 414.15 MiB | 2.89 MiB/s, done.
Resolving deltas: 100% (842352/842352), done.
Tapped 2 commands and 5615 formulae (5,929 files, 457.9MB).
Already up-to-date.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
http://docs.brew.sh/Analytics.html
==> Next steps:
- Install the Linuxbrew dependencies if you have sudo access:
Debian, Ubuntu, etc.
sudo apt-get install build-essential
Fedora, Red Hat, CentOS, etc.
sudo yum groupinstall 'Development Tools'
See http://linuxbrew.sh/#dependencies for more information.
- Add Linuxbrew to your ~/.bash_profile by running
echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >>~/.bash_profile
echo 'export MANPATH="/home/linuxbrew/.linuxbrew/share/man:$MANPATH"' >>~/.bash_profile
echo 'export INFOPATH="/home/linuxbrew/.linuxbrew/share/info:$INFOPATH"' >>~/.bash_profile
- Add Linuxbrew to your PATH
PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
- We recommend that you install GCC by running:
brew install gcc
- Run `brew help` to get started
- Further documentation:
http://docs.brew.sh
Warning: /home/linuxbrew/.linuxbrew/bin is not in your PATH.
/usr/bin/brew: 78: exec: /home/niikawa/.linuxbrew/bin/brew: not found
- brew doctor コマンドの2回目は、特に何も行われません。PATHも自動で設定された様です。
niikawa@niikawa1:~$ brew doctor
Your system is ready to brew.
niikawa@niikawa1:~$ which brew
/usr/bin/brew
tfenv のインストール
tfenv インストール前
- tfenv をインストールする前は、「Terraform v0.12.9」となります。
niikawa@niikawa1:~$ terraform -version
Terraform v0.12.9
+ provider.aws v3.37.0
Your version of Terraform is out of date! The latest version
is 0.15.3. You can update by downloading from www.terraform.io/downloads.html
tfenv のインストール
- brew installコマンドで、tfenv をインストールします。
niikawa@niikawa1:~$ brew install tfenv
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:29: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:30: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:10: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:29: warning: constant Gem::ConfigMap is deprecated
/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:30: warning: constant Gem::ConfigMap is deprecated
==> Downloading https://ghcr.io/v2/linuxbrew/core/bzip2/manifests/1.0.8-1
Already downloaded: /home/niikawa/.cache/Homebrew/downloads/47621f6c42f43a2cd6372bbf3543c1c5173f32bcb1d02a39826a0d99a432ad8b--bzip2-1.0.8-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/linuxbrew/core/bzip2/blobs/sha256:2a4cbb681a3aeda2361625bd10d329e47bf986feaccd50bf3a1
Already downloaded: /home/niikawa/.cache/Homebrew/downloads/078377a3553fa6d93748cd2888dfff050d2e046d434856a3c7950bcec03cee2c--bzip2--1.0.8.x86_64_linux.bottle.1.tar.gz
==> Downloading https://ghcr.io/v2/linuxbrew/core/unzip/manifests/6.0_7
Already downloaded: /home/niikawa/.cache/Homebrew/downloads/8ea7160a83a820cc43d63df5947fadf42bc7cfa8dd436fc45a552b641eea0b3e--unzip-6.0_7.bottle_manifest.json
==> Downloading https://ghcr.io/v2/linuxbrew/core/unzip/blobs/sha256:7f64b1d75f83c936125e0ae873668c992ca1f2041480f899b17
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:7f64b1d75f83c936125e0ae873668c992ca
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/tfenv/manifests/2.2.2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/linuxbrew/core/tfenv/blobs/sha256:89881336b91728f3fc49c497d3be4ca37cfa7b3f3357c9c0ca0
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:89881336b91728f3fc49c497d3be4ca37cf
######################################################################## 100.0%
==> Installing dependencies for tfenv: bzip2 and unzip
==> Installing tfenv dependency: bzip2
==> Pouring bzip2--1.0.8.x86_64_linux.bottle.1.tar.gz
?? /home/linuxbrew/.linuxbrew/Cellar/bzip2/1.0.8: 30 files, 549.7KB
==> Installing tfenv dependency: unzip
==> Pouring unzip--6.0_7.x86_64_linux.bottle.tar.gz
?? /home/linuxbrew/.linuxbrew/Cellar/unzip/6.0_7: 16 files, 576.4KB
==> Installing tfenv
==> Pouring tfenv--2.2.2.x86_64_linux.bottle.tar.gz
?? /home/linuxbrew/.linuxbrew/Cellar/tfenv/2.2.2: 23 files, 107.4KB
- PATH を設定します。以下はPATHの環境変数を一時的に設定していますが、ご使用の環境に応じてシェルの初期設定ファイルに追記してください。
niikawa@niikawa1:~$ PATH=/home/linuxbrew/.linuxbrew/bin:$PATH
niikawa@niikawa1:~$ which tfenv
/home/linuxbrew/.linuxbrew/bin/tfenv
- 以下の通り、tfenv コマンドが使用可能となりました。
niikawa@niikawa1:~$ tfenv
tfenv 2.2.2
Usage: tfenv []
Commands:
install Install a specific version of Terraform
use Switch a version to use
uninstall Uninstall a specific version of Terraform
list List all installed versions
list-remote List all installable versions
version-name Print current version
init Update environment to use tfenv correctly.
- tfenv のインストール可能なterraform versionを確認します。
niikawa@niikawa1:~$ tfenv list-remote
- tfenv にterraform versionを指定してインストールします。
niikawa@niikawa1:~$ tfenv list
No versions available. Please install one with: tfenv install
niikawa@niikawa1:~$ tfenv install 0.13.5
Installing Terraform v0.13.5
Downloading release tarball from https://releases.hashicorp.com/terraform/0.13.5/terraform_0.13.5_linux_amd64.zip
################################################################################################################# 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/0.13.5/terraform_0.13.5_SHA256SUMS
No keybase install found, skipping OpenPGP signature verification
Archive: tfenv_download.yfpmxn/terraform_0.13.5_linux_amd64.zip
inflating: /home/linuxbrew/.linuxbrew/Cellar/tfenv/2.2.2/versions/0.13.5/terraform
Installation of terraform v0.13.5 successful. To make this your default version, run 'tfenv use 0.13.5'
niikawa@niikawa1:~$ tfenv list
0.13.5
No default set. Set with 'tfenv use '
- tfenv にterraform versionを指定して切り替えます。
niikawa@niikawa1:~$ tfenv use 0.13.5
Switching default version to v0.13.5
Switching completed
niikawa@niikawa1:~$ tfenv list
* 0.13.5 (set by /home/linuxbrew/.linuxbrew/Cellar/tfenv/2.2.2/version)
tfenv インストール後
- tfenv をインストールした後は、「Terraform v0.13.5」となります。
niikawa@niikawa1:~$ terraform -version
Terraform v0.13.5
Your version of Terraform is out of date! The latest version
is 0.15.3. You can update by downloading from https://www.terraform.io/downloads.html
tfenv の使用方法
tfenv install [version]
- 指定のTerraform Version をインストールします。"latest" の指定は最新Versionがインストールされます。
tfenv use [version]
- Terraform のVersion を切り替えます。"latest" の指定は最新Versionに切り替わります。
tfenv uninstall <version>
- 指定のTerraform Version をアンインストールします。"latest" の指定は最新Versionがアンインストールされます。
tfenv list
- インストールされているVersion を一覧表示します。
tfenv list-remote
- インストール可能なVersion を一覧表示します。