Rubyの環境構築(IntelliJ + Docker)
#ruby #intellij #windows #wsl #docker
paizaの公開問題をRubyで解いてみようかなーってことで環境を構築することに。
ただここ最近色んな言語をホストにいれまくっててちょっと潔癖が発動し始めてる。
かるーく言語触ってみたいだけやのに、毎回ローカルに新しい言語が増えるってなんかいやじゃない?
ってことで、実行環境はDockerとかWSLにおいて、
開発だけホストのIntelliJでできないかっていうのを試してみる。
まとめ
WSLに手作りディストリビューション作ってそれを使おうとするのは無理。
もうDockerのほうが楽なレベル。
ってことで、途中までWSLでやる気でつくってたけど、Dockerに変更!!!
全く役に立たないけど途中までWSLにRubyを入れる作業について書いてる。
環境
Windows 10 Pro 64bit
WSL
Docker 19.03.8
IntelliJ 2020.1.3
Ruby 2.7.1
WSLにRuby用のディストリビューションつくっとく
WSL2で任意のディストリビューションを追加したり消したり
ここでまとめたように、Rubyってディストリビューションを用意しておく
> wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 2
podman Stopped 2
> wsl --import Ruby 'C:\wsl\distributions\Ruby' 'C:\wsl\ubuntu-20.04-server-cloudimg-amd64-wsl.rootfs.tar.gz' --version 2
> wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 2
Ruby Stopped 2
podman Stopped 2
WSLのUbuntuにRuby環境を構築
下記の記事にしたがってRubyを入れてみる
Ubuntu で最新版の Ruby をインストール - Qiita
> wsl -d Ruby
# git clone https://github.com/rbenv/rbenv.git ~/.rbenv
# git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# cd
# vi .bashrc
### PATH="$PATH:$HOME/.rbenv/bin" ### 末尾に追加
# rbenv -v
rbenv 1.1.2-30-gc879cb0
# rbenv install -l
2.5.8
2.6.6
2.7.1
jruby-9.2.12.0
maglev-1.0.0
mruby-2.1.1
rbx-5.0
truffleruby-20.1.0
# CONFIGURE_OPTS='--disable-install-rdoc' rbenv install 2.7.1
Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...
BUILD FAILED (Ubuntu 20.04 using ruby-build 20200520-14-g1642176)
Inspect or clean up the working tree at /tmp/ruby-build.20200721083236.706.Elh0wB
Results logged to /tmp/ruby-build.20200721083236.706.log
Last 10 log lines:
checking for ruby... false
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-build.20200721083236.706.Elh0wB/ruby-2.7.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
えー、Cコンパイラ要るん?
# apt update -y
# apt install -y gcc
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)
linuxは簡単にgccはいっていいなー
windowsは色々探し回って見つけられないってのがある
んで再挑戦
# CONFIGURE_OPTS='--disable-install-rdoc' rbenv install 2.7.1
Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...
BUILD FAILED (Ubuntu 20.04 using ruby-build 20200520-14-g1642176)
Inspect or clean up the working tree at /tmp/ruby-build.20200721083548.5174.sFOuWN
Results logged to /tmp/ruby-build.20200721083548.5174.log
Last 10 log lines:
checking for _setjmp as a macro or function... yes
checking for sigsetjmp as a macro or function... no
checking for setjmp type... __builtin_setjmp
checking for prefix of external symbols... NONE
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes
checking if make is GNU make... ./configure: line 29856: make: command not found
no
checking for safe null command for make... configure: error: no candidate for safe null command
まだあかん。
WindowsでWSL、Ubuntu、Rubyをインストール - Qiita
ここを参考に必要なものを一通り集める。
# apt install -y build-essential libssl-dev libreadline-dev zlib1g-dev
んで再挑戦
# CONFIGURE_OPTS='--disable-install-rdoc' rbenv install 2.7.1
Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...
Installed ruby-2.7.1 to /root/.rbenv/versions/2.7.1
# rbenv global 2.7.1
# rbenv versions
* 2.7.1 (set by /root/.rbenv/version)
# ruby -v
Command 'ruby' not found, but can be installed with:
apt install ruby
おーっと、コマンド見つからん
パスがとおってないってことなんやろうけど、rbenvで解決してもらわれへんのかー
# cd
# vi .bashrc
### PATH="$PAHT:$HOME/.rbenv/versions/2.7.1/bin" ### 末尾に追加
# ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) x86_64-linux
おしゃはいったー
IntelliJでRemoteSDKを指定したプロジェクトの作成
まずRubyのプラグインは入っているものとします。
その状態でNew Project...したら、Rubyが選択肢にあると思います。
ただ、Project SDKが <No SDK> と表示されて悲しい感じになります。
https://gyazo.com/e4f116ef7685b17420dd2e4ec89ffd9a
ここで、No SDKになってるところを選択すると、
Add Ruby SDK...があり、これを選択すると、
New remote...があります。これです。
https://gyazo.com/5148621d67687180bcab574026c4959a
WSLを選択し、Linux Distributionを選択すると
https://gyazo.com/c32e3e2db76182b0a98ae8cdfe1cebf8
あれ、作ったRubyがなーい。
これどうも、手作りのはダメでデフォルトのディストリビューションしかダメっぽいなー。
ってことでさくっとwslをあきらめて、Dockerに切り替える。
https://gyazo.com/37a7ea8b55e2ccd14123cca5d4c19199
ちょっと待てばリモートSDKが作られて、選ばれた状態になる。
https://gyazo.com/36f0eeb8919b9679448b8e4625ca77f5
Hello, World
https://gyazo.com/14297032855cfe9c1bd80f73809e944c
おわりに
環境構築はIntelliJにお任せ☆
#2020/07/19週
2020/07/21 公開