deploygateが入らない - macOSにdgコマンドをインストールする

CLIからDeplyGateを利用できるdgコマンドですが、macOSでは通常コマンド一発で入ります。

$ curl -sSL https://deploygate.com/cli/install | bash

$ dg --version
dg 0.7.0

ところが環境によってはエラーとの戦いに突入しすんなり入ってくれません。というかなりました。Ruby製のソフトウェアはこの手の問題が発生しやすいイメージが強いのですが何とかならんもんですかね…(´・ω・`) Rubyと聞くと反射的に「ウッ」と変な声が出るようになりましたよw 自分でゼロから書く分には良いのでしょうが。

閑話休題。というわけで今回はmacOS Mojava(10.14.6)にdgコマンドを入れます。

なお、XCodeのコマンドラインツールは事前にインストールしておいてください。2行目はライセンスに同意するコマンドです。普通にXCodeを起動してボタンをクリックしても大丈夫です。

$ xcode-select --install
$ sudo xcodebuild -license accept

その1「Can't find header files ruby.h」

第一の関門はヘッダーファイルが無いというエラー。

$ curl -sSL https://deploygate.com/cli/install | bash
ERROR:  Error installing deploygate:
ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.3.0/gems/unf_ext-0.0.7.6/ext/unf_ext

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20191030-50381-xdai09.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/unf_ext-0.0.7.6 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/unf_ext-0.0.7.6/gem_make.out

こちらはStackOverflowでズバリの回答があったのでお世話になりました。

openコマンドを実行するとGUIのインストーラーが起動して必要なファイルをインストールしてくれます。

$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

その2「requires Ruby version >= 2.4.0.」

これはもう単純にmacOSに最初から入っているRubyのバージョンが古いからですね。

$ curl -sSL https://deploygate.com/cli/install | bash
ERROR:  Error installing deploygate:
signet requires Ruby version >= 2.4.0.

はいきたー。

$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

ダメな方法

もう面倒だったのでbrewでそのままRubyを入れれば良いかと思い、以下のようにインストールしました。

$ brew info ruby
ruby: stable 2.6.5 (bottled), HEAD [keg-only]

$ brew install ruby
$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"'     >> ~/.bash_profile
$ echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"'      >> ~/.bash_profile
$ echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile
$ source ~/.bash_profile

はいきたー。

$ ruby --version
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

はいきたーorz

$ curl -sSL https://deploygate.com/cli/install | bash
ERROR:  Error installing deploygate:
"bundle" from bundler conflicts with /usr/local/lib/ruby/gems/2.6.0/bin/bundle

パスの設定とか頑張れば解決しそうなんですが、心が折れたのでrbenvでちゃんと入れようとか思います。というわけで、とりあえず一旦削除します。

$ brew remove ruby
Uninstalling /usr/local/Cellar/ruby/2.6.5... (19,390 files, 31.1MB)

~/.bash_profileへ追加したPATHの設定も削除しておきます。

rbenvでRubyを入れる

今度はrbenvで入れてみます。Rubyのバージョンを指定して自由自在に切り替えることができる便利ツールです。

まずはrbenvそのものを入れます。

$ brew install rbenv ruby-build
$ rbenv --version
rbenv 1.1.2

rbenvの初期設定をします。

$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bashrc:

eval "$(rbenv init -)"

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

rbenvでインストール可能なバージョンを確認します。今回は2.6.5を入れることにします。

$ rbenv install --list
Available versions:
  1.8.5-p52
  1.8.5-p113
  (中略)
  2.6.4
  2.6.5
  2.7.0-dev
  2.7.0-preview1
  2.7.0-preview2

指定したバージョンをインストールし、利用するバージョンを選択します。

$ rbenv install 2.6.5
$ rbenv global 2.6.5
$ ruby --version
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

はいきたー。

$ rbenv versions
  system
* 2.6.5 (set by /Users/katsube/.rbenv/version)

エピローグ

・::・:┣¨キ(゚Д゚)┣¨キ:・::・

$ curl -sSL https://deploygate.com/cli/install | bash
Welcome to DeployGate!

         _            _                       _
        | |          | |                     | |
      __| | ___  ___ | | ___ _   ,____   ___ | |_ ___
     / _` |/ _ \' _ \| |/ _ \ \ / / _ \ / _ `| __/ _ \
    | (_| |  __/ |_) | | (_) \ v / (_| | (_| | |_' __/
     \___, \___| .__/|_|\___/ ` / \__, |\__,_|\__\___`
               |_|           /_/  |___/

Installing dg with "gem install deploygate --no-document".

This may take a while. It's a good time to grab some coffee ☕️

Fetching CFPropertyList-3.0.1.gem
Fetching httpclient-2.8.3.gem
Fetching plist-3.5.0.gem
Fetching commander-4.4.6.gem
Fetching highline-1.7.10.gem
Fetching claide-1.0.3.gem
Fetching atomos-0.1.3.gem
Fetching json-1.8.6.gem
Fetching colored2-3.1.2.gem
Fetching nanaimo-0.2.6.gem
Fetching xcodeproj-1.13.0.gem
Fetching systemu-2.6.5.gem
Fetching macaddr-1.7.2.gem
Fetching uuid-2.3.9.gem
Fetching gem_update_checker-0.2.0.gem
Fetching thread_safe-0.3.6.gem
Fetching tzinfo-1.2.5.gem
Fetching concurrent-ruby-1.1.5.gem
Fetching i18n-0.9.5.gem
Fetching activesupport-4.2.11.1.gem
Fetching public_suffix-2.0.5.gem
Fetching addressable-2.7.0.gem
Fetching launchy-2.4.3.gem
Fetching locale-2.1.2.gem
Fetching net-ping-2.0.6.gem
Fetching websocket-1.2.8.gem
Fetching event_emitter-0.2.6.gem
Fetching websocket-client-simple-0.3.0.gem
Fetching multi_xml-0.6.0.gem
Fetching mime-types-data-3.2019.1009.gem
Fetching mime-types-3.3.gem
Fetching httparty-0.17.1.gem
Fetching socket.io-client-simple-1.2.1.gem
Fetching workers-0.6.1.gem
Fetching multipart-post-2.0.0.gem
Fetching faraday-0.17.0.gem
Fetching sentry-raven-2.12.2.gem
Fetching slack-notifier-2.3.2.gem
Fetching rouge-2.0.7.gem
Fetching xcpretty-0.3.0.gem
Fetching terminal-notifier-2.0.0.gem
Fetching unicode-display_width-1.6.0.gem
Fetching terminal-table-1.8.0.gem
Fetching word_wrap-1.0.0.gem
Fetching tty-screen-0.7.0.gem
Fetching tty-cursor-0.7.0.gem
Fetching tty-spinner-0.9.1.gem
Fetching babosa-1.0.3.gem
Fetching colored-1.2.gem
Fetching commander-fastlane-4.4.6.gem
Fetching excon-0.68.0.gem
Fetching unf_ext-0.0.7.6.gem
Fetching unf-0.1.4.gem
Fetching domain_name-0.5.20190701.gem
Fetching http-cookie-1.0.3.gem
Fetching faraday-cookie_jar-0.0.6.gem
Fetching faraday_middleware-0.13.1.gem
Fetching fastimage-2.1.7.gem
Fetching gh_inspector-1.1.3.gem
Fetching mini_magick-4.9.5.gem
Fetching rubyzip-1.3.0.gem
Fetching security-0.1.3.gem
Fetching xcpretty-travis-formatter-1.0.0.gem
Fetching dotenv-2.7.5.gem
Fetching naturally-2.2.0.gem
Fetching simctl-1.6.6.gem
Fetching jwt-2.1.0.gem
Fetching multi_json-1.14.1.gem
Fetching signet-0.12.0.gem
Fetching os-1.0.1.gem
Fetching memoist-0.16.0.gem
Fetching googleauth-0.6.7.gem
Fetching retriable-3.1.2.gem
Fetching declarative-option-0.1.0.gem
Fetching declarative-0.0.10.gem
Fetching uber-0.1.0.gem
Fetching representable-3.0.4.gem
Fetching google-api-client-0.23.9.gem
Fetching digest-crc-0.4.1.gem
Fetching google-cloud-env-1.3.0.gem
Fetching google-cloud-core-1.4.1.gem
Fetching google-cloud-storage-1.16.0.gem
Fetching emoji_regex-1.0.1.gem
Fetching fastlane-2.134.0.gem
Fetching deploygate-0.7.0.gem
Building native extensions. This could take a while...
Successfully installed json-1.8.6
Successfully installed httpclient-2.8.3
Successfully installed highline-1.7.10
Successfully installed commander-4.4.6
Successfully installed plist-3.5.0
Successfully installed atomos-0.1.3
Successfully installed CFPropertyList-3.0.1
Successfully installed claide-1.0.3
Successfully installed colored2-3.1.2
Successfully installed nanaimo-0.2.6
Successfully installed xcodeproj-1.13.0
Successfully installed systemu-2.6.5
Successfully installed macaddr-1.7.2
Successfully installed uuid-2.3.9
Successfully installed gem_update_checker-0.2.0
Successfully installed thread_safe-0.3.6
Successfully installed tzinfo-1.2.5
Successfully installed concurrent-ruby-1.1.5
Successfully installed i18n-0.9.5
Successfully installed activesupport-4.2.11.1
Successfully installed public_suffix-2.0.5
Successfully installed addressable-2.7.0
Successfully installed launchy-2.4.3
Successfully installed locale-2.1.2
Successfully installed net-ping-2.0.6
Successfully installed websocket-1.2.8
Successfully installed event_emitter-0.2.6
Successfully installed websocket-client-simple-0.3.0
Successfully installed multi_xml-0.6.0
Successfully installed mime-types-data-3.2019.1009
Successfully installed mime-types-3.3
When you HTTParty, you must party hard!
Successfully installed httparty-0.17.1
Successfully installed socket.io-client-simple-1.2.1
Successfully installed workers-0.6.1
Successfully installed multipart-post-2.0.0
Successfully installed faraday-0.17.0
Successfully installed sentry-raven-2.12.2
Successfully installed slack-notifier-2.3.2
Successfully installed rouge-2.0.7
Successfully installed xcpretty-0.3.0
Successfully installed terminal-notifier-2.0.0
Successfully installed unicode-display_width-1.6.0
Successfully installed terminal-table-1.8.0
Successfully installed word_wrap-1.0.0
Successfully installed tty-screen-0.7.0
Successfully installed tty-cursor-0.7.0
Successfully installed tty-spinner-0.9.1
Successfully installed babosa-1.0.3
Successfully installed colored-1.2
Successfully installed commander-fastlane-4.4.6
Successfully installed excon-0.68.0
Building native extensions. This could take a while...
Successfully installed unf_ext-0.0.7.6
Successfully installed unf-0.1.4
Successfully installed domain_name-0.5.20190701
Successfully installed http-cookie-1.0.3
Successfully installed faraday-cookie_jar-0.0.6
Successfully installed faraday_middleware-0.13.1
Successfully installed fastimage-2.1.7
Successfully installed gh_inspector-1.1.3
Successfully installed mini_magick-4.9.5
Successfully installed rubyzip-1.3.0
Successfully installed security-0.1.3
Successfully installed xcpretty-travis-formatter-1.0.0
Successfully installed dotenv-2.7.5
Successfully installed naturally-2.2.0
Successfully installed simctl-1.6.6
Successfully installed jwt-2.1.0
Successfully installed multi_json-1.14.1
Successfully installed signet-0.12.0
Successfully installed os-1.0.1
Successfully installed memoist-0.16.0
Successfully installed googleauth-0.6.7
Successfully installed retriable-3.1.2
Successfully installed declarative-option-0.1.0
Successfully installed declarative-0.0.10
Successfully installed uber-0.1.0
Successfully installed representable-3.0.4
Successfully installed google-api-client-0.23.9
Successfully installed digest-crc-0.4.1
Successfully installed google-cloud-env-1.3.0
Successfully installed google-cloud-core-1.4.1
Successfully installed google-cloud-storage-1.16.0
Successfully installed emoji_regex-1.0.1
Successfully installed fastlane-2.134.0

dg installed! To get started fast:

  $ dg deploy

Successfully installed deploygate-0.7.0
85 gems installed

はいきたー!

$ dg --version
dg 0.7.0

|\○ヒャッ ε=\_○ノ ホーウ!!