LoginSignup
2
1

More than 1 year has passed since last update.

さくらvpsにRailsアプリをデプロイするまで (4) Homebrew導入

Posted at

1. Homebrewを入れたい

 ローカルと同様に、さくらvpsにもHomebrewを入れてみようと思った。ひとまず公式ページから以下の文面をコピペしてやってみる。

# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

そうするとエラーが出た。

略....
curl: (1) Protocol "https" not supported or disabled in libcurl

curlがhttpsに対応してないらしい。なんと。ためしにcurl -V とやるといっぱいでてきたけどhttpsの文字はなかった。
コピーをとってなかったが、たしか初期にあったバージョンはcurl v 7.2くらいだった。

yumでcurlのバージョンアップをしようとしたが、バージョンが上がらなかった。どうしよう。パッケージからやっていくことにした。

2. Homebrewを入れるためにcurlを入れる

ここからcurl-7.82.0.tar.gzを入れることにする。#wget で指定したURLのファイルをダウンロードする。そして #tarで展開する。

# wget https://curl.se/download/curl-7.82.0.tar.gz

# tar -xvzf curl-7.82.0.tar.gz

その後は公式ドキュメントを読みながらやる。
https://curl.se/docs/install.html

tarでたくさんのファイルが出てくる。そのうちのひとつに./configureがある。 おそらく次のコマンドでconfigureファイルをつかって何かをしているはずである。

# ./configure --with-openssl

これがちょっと一筋縄ではいかなかった。たくさんエラーが出てきた。

configure: error: --with-openssl was given but OpenSSL could not be detected

OpenSSLを指定しているが、見つからなかったとのこと。openssl versionとやったら出てくるので、さくらvpsにはインストールされている。パスの設定がいろいろ必要だったのだろう。その後、いろいろ試したが結局あたらしいopensslをインストールしなおすことにした。

3. culrを入れるためにopenssl 1.1.1を入れる

ここを参考に。

# cd /usr/local/src/
# wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
# tar xzvf openssl-1.1.1k.tar.gz 
# cd openssl-1.1.1k
# ./config --prefix=/usr/local/openssl shared zlib

エラーが出た。

crypto/comp/c_zlib.c:35:19: fatal error: zlib.h: No such file or directory
 # include <zlib.h>
                   ^
compilation terminated.

zlibというのが入っていないとのこと。

yum install zlib-devel

installした。

# ./configure --with-openssl=/usr/local/openssl
# make
# make install

こうするとopensslが入った。

4. opensslを共有ライブラリへ追加

CentOSは共有ライブラリという概念があって、単純にインストールしてもその設定をしないとだめらしい。パスを通すようなものか。

以下の手順はこちらのサイトと同様だ。

追加前の状態を確認する。

# ldconfig -p | grep libssl
	libssl3.so (libc6,x86-64) => /lib64/libssl3.so
	libssl.so.10 (libc6,x86-64) => /lib64/libssl.so.10

lib64というところにだけはいっている。

/etc/ld.so.conf.d/openssl-1.1.1.conf を作成する。

中身はこのようにする。

/etc/ld.so.conf.d/openssl-1.1.1.conf
/usr/local/openssl-1.1.1/lib

キャッシュファイルを更新する

# ldconfig
# ldconfig -p | grep libssl
	libssl3.so (libc6,x86-64) => /lib64/libssl3.so
	libssl.so.10 (libc6,x86-64) => /lib64/libssl.so.10
	libssl.so.1.1 (libc6,x86-64) => /usr/local/openssl/lib/libssl.so.1.1
	libssl.so (libc6,x86-64) => /usr/local/openssl/lib/libssl.so

5. curlを入れ直す

やっとここまできた。公式を参考にcurlの./configureをなんとかする。
curlのファイル群があるところにカレントディレクトリを移動させてから以下を打ち込む。

公式の文章

The configure script always tries to find a working SSL library unless explicitly told not to. If you have OpenSSL installed in the default search path for your compiler/linker, you do not need to do anything special. If you have OpenSSL installed in /usr/local/ssl, you can run configure like:

./configure --with-openssl

If you have OpenSSL installed somewhere else (for example, /opt/OpenSSL) and you have pkg-config installed, set the pkg-config path first, like this:

env PKG_CONFIG_PATH=/opt/OpenSSL/lib/pkgconfig ./configure --with-openssl

Without pkg-config installed, use this:

./configure --with-openssl=/opt/OpenSSL

今回は/usr/local/opensslにopensslがあるので以下のようにする。

# ./configure --with-openssl=/usr/local/openssl
# make
# make install

curlが入った。どうだろう。

 curl -V
curl 7.82.0 (x86_64-pc-linux-gnu) libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0
Release-Date: 2022-03-05
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets
WARNING: curl and libcurl versions do not match. Functionality may be affected.

まだエラーが出た。でももう一回ldconfigをやったらなおった。

6. Homebrewを入れてみる

そうして紆余曲折を経て、Homebrewを入れる。

rootユーザーでは実行できないはずなので、ログインするユーザーになってやる。

# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)"
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
test -r ~/.bash_profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile
echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.profile

無事にインストールはできた。

brew -v
Homebrew 3.4.5-16-gf6ab300
Homebrew/homebrew-core (no Git repository)

でもなんかおかしい。

7. brew doctorでみてみる

おかしいときはbrew doctorで診断ができる。

[vpuser@os3-317-48322 ~]$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Homebrew/homebrew-core was not tapped properly! Run:
  rm -rf "/home/vpuser/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core"
  brew tap homebrew/core

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew-provided
script of the same name. We found the following "config" scripts:
  /usr/local/bin/curl-config
...

いろいろ忠告が出てきた。素直に上からやっていく。

$ rm -rf "/home/vpuser/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core"

$ brew tap homebrew/core

これをやると

]$ brew -v
Homebrew 3.4.5-16-gf6ab300
Homebrew/homebrew-core (git revision 2e035b9d6e2; last commit 2022-04-05)

無事にできた。

8. おわり

 長いたたかいだった。

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