Ruby on Rails是一个免费的开放源代码Web应用程序框架,可帮助您使用Ruby创建网站。Rails是一个模型视图控制器框架,该框架将Ruby编程语言与JavaScript,HTML和CSS相结合,以编写在Web服务器上运行的Web应用程序,并简化了常见的重复任务。Rails附带了一组约定,这些约定可以帮助开发人员在不花费大量时间进行文件配置的情况下加快开发速度。
在本教程中,我们将向您展示如何在CentOS 8服务器上安装Ruby on Rails框架。
要求
- 运行CentOS的服务器8。
- 在服务器上配置了root密码。
安装Ruby
使用RVM安装Ruby的最简单方法。RVM也称为“ Ruby版本管理器”,是一个命令行工具,可用于安装和管理来自解释器的不同Ruby版本。
首先,使用以下命令安装curl和gnupg2软件包:
dnf install curl gnupg2 -y
接下来,您将需要在系统上导入RVM公钥:
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
您应该看到以下输出:
gpg: key 105BD0E739499BDB: 8 signatures not checked due to missing keys gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported gpg: key 3804BB82D39DC0E3: 108 signatures not checked due to missing keys gpg: key 3804BB82D39DC0E3: "Michal Papis (RVM signing) <mpapis@gmail.com>" not changed gpg: no ultimately trusted keys found gpg: Total number processed: 2 gpg: imported: 1 gpg: unchanged: 1
接下来,使用以下命令下载并安装RVM的最新稳定版本:
curl -sSL https://get.rvm.io | bash -s stable
一旦安装了RVM,您将获得以下输出:
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc gpg: Signature made Wednesday 10 July 2019 04:31:02 AM EDT 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.9.tgz' Creating group 'rvm' Installing RVM to /usr/local/rvm/ Installation of RVM in /usr/local/rvm/ is almost complete:
接下来,使用以下命令激活RVM环境变量:
source /etc/profile.d/rvm.sh
接下来,通过运行以下命令来安装所有Ruby依赖项:
rvm requirements
安装所有依赖项后,您应该看到以下输出:
Checking requirements for centos. Installing requirements for centos. Installing required packages: patch, autoconf, automake, bison, 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 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[.6] [ruby-]2.5[.5] [ruby-]2.6[.3] [ruby-]2.7[.0-preview1] ruby-head
现在,您可以使用以下命令安装Ruby版本2.6.3:
rvm install 2.6.3
接下来,运行以下命令以将版本2.6.3设置为默认版本:
rvm use 2.6.3 --default
输出:
使用/usr/local/rvm/gems/ruby-2.6.3
您还可以使用以下命令验证Ruby的安装版本:
ruby --version
输出:
ruby 2.6.3p62(2019-04-16修订版67580)[x86_64-linux]
安装滑轨
您可以使用gem命令安装最新版本的Rails,如下所示:
gem install rails
安装Rails后,可以使用以下命令检查Rails版本:
rails -v
您应该看到以下输出:
Rails 6.0.2.1
结论
在以上教程中,您学习了如何在CentOS 8服务器上安装Ruby on Rails。
原文:https://www.howtoforge.com/how-to-install-ruby-on-rails-on-centos-8/