CentOS 7 리눅스에서 RVM을 이용해 Ruby 버전 관리하기

CentOS 7 리눅스에서 RVM을 이용해 Ruby를 쉽고 빠르게 설치하는 방법을 알려드립니다. RVM은 Ruby 버전 관리를 편리하게 해주는 도구로, 여러 버전의 Ruby를 한 시스템에서 사용할 수 있습니다.
인프라코디
CentOS 7 리눅스에서 RVM을 이용해 Ruby 버전 관리하기

루비(Ruby)를 설치하는 다양한 방법 중 루비 버전 관리자(RVM)를 사용한 Ruby 설치 방법에 대해 알아봅니다. CentOS 7에서 Ruby 설치 도구인 루비 버전 관리자(RVM : Ruby Version Manager)를 사용하여 다양한 버전의 Ruby를 설치하고, 루비 기본 버전 설정을 통해 다양한 Ruby 개발 환경을 구성할 수 있습니다.

이 문서에서는 다음 방법을 설명합니다.

  • 루비 버전 관리자(RVM : Ruby Version Manager) 설치 방법
  • 루비 버전 관리자(RVM : Ruby Version Manager)를 사용해서 Ruby 설치 방법
  • 루비 버전 관리자(RVM : Ruby Version Manager)를 사용해서 Ruby 기본 버전으로 설정 방법

사전 요구 사항

  • sudo 실행 권한이 있는 사용자 또는 root 계정으로 실행하기
  • sudo 실행 권한이 있는 사용자 계정으로 실행할 때에는 sudo 명령어와 함께 실행하기
  • RVM 설치를 위해 curl 명령어를 사용하므로 설치되어 있지 않으면 yum install -y curl 명령을 실행해서 설치하기

환경 정보

  • 운영 체제 : CentOS 7.9 x86_64
  • 로그인 계정 : root
  • RVM 설치 버전 : 1.29.12
  • Ruby 설치 버전 : 2.7.2

RVM(Ruby Version Manager) 설치하기

Ruby 설치 도구 루비 버전 관리자(RVM)를 먼저 설치합니다.

RVM GPG key 설치하기

RVM 공식 홈페이지에서 패키지를 다운로드하기 위해 키를 설치합니다.

curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
[root@infracody.com ~]# curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import - gpg: directory '/root/.gnupg' created gpg: keybox '/root/.gnupg/pubring.kbx' created gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported gpg: Total number processed: 1 gpg: imported: 1

RVM 설치 스크립트 다운로드 및 실행하기

RVM 설치 스크립트를 실행하여 안정 버전을 설치합니다.

curl -sSL https://get.rvm.io | bash -s stable
[root@infracody.com ~]# curl -sSL https://get.rvm.io | bash -s stable Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc gpg: Signature made Sat 16 Jan 2021 03:46:22 AM KST gpg: using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB gpg: Good signature from "Piotr Kuczynski <piotr.kuczynski@gmail.com>" [unknown] gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB GPG verified '/usr/local/rvm/archives/rvm-1.29.12.tgz' Creating group 'rvm' Installing RVM to /usr/local/rvm/ Installation of RVM in /usr/local/rvm/ is almost complete: * First you need to add all users that will be using rvm to 'rvm' group, and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`. * To start using RVM you need to run `source /etc/profile.d/rvm.sh` in all your open shell windows, in rare cases you need to reopen all shell windows. * Please do NOT forget to add your users to the rvm group. The installer no longer auto-adds root or users to the rvm group. Admins must do this. Also, please note that group memberships are ONLY evaluated at login time. This means that users must log out then back in before group membership takes effect! Thanks for installing RVM 🙏 Please consider donating to our open collective to help us maintain RVM. 👉 Donate: https://opencollective.com/rvm/donate
설치가 완료되면 rvm 그룹이 자동으로 생성되며, rvm을 사용할 모든 사용자를 rvm 그룹에 추가해야 합니다. source /etc/profile.d/rvm.sh 명령을 실행하면 로그 아웃 하지 않아도 rvm 명령을 사용할 수 있습니다.

Rails도 함께 설치하고 싶으면 아래와 같이 실행합니다.

curl -sSL https://get.rvm.io | bash -s stable --rails

시스템 환경 변수 및 RVM 정보 업데이트하기

Ruby 환경 설정 파일을 실행하여 설치 정보를 업데이트 합니다.

source /etc/profile.d/rvm.sh
rvm reload

RVM 의존성 패키지 설치하기

yum install을 사용해서 미리 설치할 수도 있지만, RVM이 필요한 패키지를 확인하고 자동으로 설치해 주므로 아래 명령을 실행해서 의존성 패키지를 설치합니다.

rvm requirements run
[root@infracody.com ~]# rvm requirements run Checking requirements for centos. Installing requirements for centos. Installing required packages: patch, autoconf, automake, bison, bzip2, gcc-c++, libffi-devel, libtool, make, patch, readline-devel, ruby, sqlite-devel, zlib-devel, glibc-headers, glibc-devel, openssl-devel................................. Requirements installation successful.

Ruby 설치하기

RVM을 사용해서 간단하게 Ruby를 설치할 수 있습니다. 다양한 버전의 Ruby를 설치할 수 있으며, 기본 버전을 선택해서 사용합니다.

설치 가능한 Ruby 버전 정보 확인하기

설치할 수 있는 Ruby 버전을 확인합니다.

rvm list known
[root@infracody.com ~]# rvm list known # MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-head] # security released on head [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p330] [ruby-]1.9.3[-p551] [ruby-]2.0.0[-p648] [ruby-]2.1[.10] [ruby-]2.2[.10] [ruby-]2.3[.8] [ruby-]2.4[.10] [ruby-]2.5[.8] [ruby-]2.6[.6] [ruby-]2.7[.2] [ruby-]3[.0.0] ruby-head # for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2 # JRuby jruby-1.6[.8] jruby-1.7[.27] jruby-9.1[.17.0] jruby[-9.2.14.0] jruby-head # Rubinius rbx-1[.4.3] rbx-2.3[.0] rbx-2.4[.1] rbx-2[.5.8] rbx-3[.107] rbx-4[.20] rbx-5[.0] rbx-head # TruffleRuby truffleruby[-20.3.0] # Opal opal # Minimalistic ruby implementation - ISO 30170:2012 mruby-1.0.0 mruby-1.1.0 mruby-1.2.0 mruby-1.3.0 mruby-1[.4.1] mruby-2.0.1 mruby-2[.1.1] mruby[-head] # Ruby Enterprise Edition ree-1.8.6 ree[-1.8.7][-2012.02] # Topaz topaz # MagLev maglev-1.0.0 maglev-1.1[RC1] maglev[-1.2Alpha4] maglev-head # Mac OS X Snow Leopard Or Newer macruby-0.10 macruby-0.11 macruby[-0.12] macruby-nightly macruby-head # IronRuby ironruby[-1.1.3] ironruby-head

Ruby 설치 및 버전 지정하기

레드마인(Redmine)의 최신 버전인 4.2.1에서 지원되는 최신 버전인 Ruby 2.7을 설치합니다.

다른 버전도 같이 설치하고 사용할 수 있습니다.

rvm install 2.7
[root@infracody.com ~]# rvm install 2.7 Searching for binary rubies, this might take some time. No binary rubies available for: centos/8/x86_64/ruby-2.7.2. Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies. Checking requirements for centos. Requirements installation successful. Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.7.2, this may take a while depending on your cpu(s)... ruby-2.7.2 - #downloading ruby-2.7.2, this may take a while depending on your connection... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 14.0M 100 14.0M 0 0 2638k 0 0:00:05 0:00:05 --:--:-- 3438k ruby-2.7.2 - #extracting ruby-2.7.2 to /usr/local/rvm/src/ruby-2.7.2..... ruby-2.7.2 - #configuring........................................................................ ruby-2.7.2 - #post-configuration.. ruby-2.7.2 - #compiling............................................................................................ ruby-2.7.2 - #installing.................. ruby-2.7.2 - #making binaries executable... Installed rubygems 3.1.4 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation. ruby-2.7.2 - #gemset created /usr/local/rvm/gems/ruby-2.7.2@global ruby-2.7.2 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................ ruby-2.7.2 - #generating global wrappers........ ruby-2.7.2 - #gemset created /usr/local/rvm/gems/ruby-2.7.2 ruby-2.7.2 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.7.2 - #generating default wrappers........ ruby-2.7.2 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake). Install of ruby-2.7.2 - #complete Ruby was built without documentation, to build it run: rvm docs generate-ri

RVM으로 설치된 패키지 리스트를 확인합니다.

rvm list
[root@infracody.com ~]# rvm list =* ruby-2.7.2 [ x86_64 ] # => - current # =* - current && default # * - default

설치한 Ruby 2.7.2를 기본 버전으로 적용합니다.

rvm use 2.7 --default
[root@infracody.com ~]# rvm use 2.7 --default Using /usr/local/rvm/gems/ruby-2.7.2

Ruby 버전을 확인합니다.

ruby -v
[root@infracody.com ~]# ruby -v ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]

마무리

CentOS 7에서 루비 버전 관리자(RVM : Ruby Version Manager)를 설치하고, RVM을 사용해서 Ruby 설치 및 기본 버전 설정 방법에 대해 알아보았습니다. 여러 버전의 Ruby를 설치하고, 다양한 Ruby 개발 환경을 구축하여 사용할 수 있습니다.

인프라코디
서버, 네트워크, 보안 등 IT 인프라 관리를 하는 시스템 엔지니어로 일하고 있으며, IT 기술 정보 및 일상 정보를 기록하는 블로그를 운영하고 있습니다. 글을 복사하거나 공유 시 게시하신 글에 출처를 남겨주세요.

- 블로그 : www.infracody.com

이 글이 유익했나요? 댓글로 소중한 의견을 남겨주시거나 커피 한 잔의 선물은 큰 힘이 됩니다.
댓글