Ruby をアップデートする

Mastodon

今の環境には apt で ruby と ruby-dev をインストールしている。
これを、最新バージョンをインストールするために rbenv でインストールするよう変更する。
ただ、ubuntu のリポジトリで配布されている rbenvパッケージは古いらしいので、Mastodon 公式サイトを参考に git を使って最新バージョンの rbenv で ruby をインストールする。

 

サービスの停止

sudo systemctl stop mastodon-web mastodon-sidekiq mastodon-streaming

 

ユーザー mastodon に変更

今回はシステム全体ではなく、ユーザー(mastodon)用に Ruby をインストールする。

sudo su - mastodon
cd ~/

 

rbenv と rbenv-build のインストール

追加する PATH を ~/.bashrc に書き込む。

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec bash
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

.bashrc は sudo su - mastodon を実行したときは読み込まれないから、.bash_profile を作って対応する。
内容は1行だけ。

vi ~/.bash_profile
source ~/.bashrc

 

rbenv のバージョン確認

$ rbenv -v
rbenv 1.3.0-4-gc335ab8

 

インストール可能 Ruby のバージョン確認

$ rbenv install -l
3.1.6
3.2.5
3.3.4
jruby-9.4.8.0
mruby-3.3.0
picoruby-3.0.0
truffleruby-24.0.2
truffleruby+graalvm-24.0.2

Only latest stable releases for each Ruby implementation are shown.
Use `rbenv install --list-all' to show all local versions.

 

Ruby のインストール

$ RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.3.4
==> Downloading ruby-3.3.4.tar.gz...
-> curl -q -fL -o ruby-3.3.4.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.4.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.0M  100 21.0M    0     0  32.8M      0 --:--:-- --:--:-- --:--:-- 32.8M
==> Installing ruby-3.3.4...
-> ./configure "--prefix=$HOME/.rbenv/versions/3.3.4" --enable-shared --with-ext=openssl,psych,+ --with-jemalloc
-> make -j 4
-> make install
==> Installed ruby-3.3.4 to /home/mastodon/.rbenv/versions/3.3.4

NOTE: to activate this Ruby version as the new default, run: rbenv global 3.3.4
$ rbenv global 3.3.4

一応 rbenv global 3.3.4 を実行したものの、.ruby-version のほうが優先されるらしい。

 

bundler のインストールと gem アップデート

bundler はアップデート時も同じコマンドで最新版がインストールされる。

$ gem install bundler --no-document
$ gem update --system

 

Ruby バージョンの変更

cd ~/.live
vi ./.ruby-version 
3.3.4

 

bundle の実行

Ruby のバージョンが変わったから bundle (bundle install と同じ)を実行する。
Bundler は最新版の 2.5.18 になっているけれど、lockfile が 2.4.13 で生成されているから Bundler 2.4.13 がインストールされた。

$ bundle
Bundler 2.5.18 is running, but your lockfile was generated with 2.4.13. Installing Bundler 2.4.13 and restarting using that version.
Fetching gem metadata from https://rubygems.org/.
Fetching bundler 2.4.13
Installing bundler 2.4.13
Fetching gem metadata from https://rubygems.org/.........
Fetching https://github.com/stanhu/omniauth-cas.git
Fetching https://github.com/mastodon/rails-settings-cached.git
Fetching https://github.com/ClearlyClaire/webpush.git
Fetching rake 13.0.6
Installing rake 13.0.6
Fetching concurrent-ruby 1.2.3

・・・長いので省略

LXC(CT)を再起動してから改めて bundle install を実行したら、動作中の bundler も最新版になっていた。

動作中の bundler のバージョンとインストールされているバージョンは次で確認できる。

$ bundle -v
Bundler version 2.5.18
$ gem info bundler

*** LOCAL GEMS ***

bundler (2.5.18)
    Authors: André Arko, Samuel Giddins, Colby Swandale, Hiroshi
    Shibata, David Rodríguez, Grey Baker, Stephanie Morillo, Chris
    Morris, James Wen, Tim Moore, André Medeiros, Jessica Lynn Suttles,
    Terence Lee, Carl Lerche, Yehuda Katz
    Homepage: https://bundler.io
    License: MIT
    Installed at: /home/mastodon/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0

    The best way to manage your application's dependencies
$ gem list | grep bundler
bundler (2.5.18)

 

ここまでユーザー mastodon で実行した。
以降は root での作業となる。

 

mastodon-*.service の実行

オリジナルの mastodon-*.service に戻してサービスを起動する。

systemctl disable mastodon-web mastodon-sidekiq mastodon-streaming
cp /home/mastodon/live/dist/mastodon*.service /etc/systemd/system
systemctl daemon-reload
systemctl enable mastodon-web mastodon-sidekiq mastodon-streaming
systemctl start mastodon-web mastodon-sidekiq mastodon-streaming

systemctl status mastodon-*.service を確認してエラーが出ていなければ OK。

 

Elasticsearch と kuromoji のインストール

インストールする Elasticsearch バージョンは kuromoji の最新版に合わせて 7.17.23 とする。
こちらのサイト「ほしぱそ。」に丁寧な解説があって助かりました。ありがとう。

古い kuromoji の削除

/usr/share/elasticsearch/bin/elasticsearch-plugin remove analysis-kuromoji

Elasticsearch と kuromoji のインストールとバージョン固定

本日時点の 7.* 系の最新バージョンをインストールする。

apt install --reinstall elasticsearch=7.17.23
apt-mark hold elasticsearch
wget https://artifacts.elastic.co/downloads/elasticsearch-plugins/analysis-kuromoji/analysis-kuromoji-7.17.23.zip
 /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///root/analysis-kuromoji-7.17.23.zip

 

 

以上で Ruby(と全文検索)のアップデートは完了。
apt じゃなく、最初から rbenv で管理していればもう少し楽だったような・・・。