在本文中,我们将学习如何设置和配置Ruby on Rails,它是开发人员使用的最流行的堆栈应用程序,通常用于创建站点和Web应用程序。Ruby是一种编程语言,程序员可以结合使用Rails开发框架来使应用程序开发变得快速而简单。
“ RVM”(Ruby版本管理器)是用于安装Ruby和Rails的命令行工具,它还为使用Ruby on Rails进行应用程序开发提供了良好的环境,还可以提供多个Ruby环境。
我们需要具有非root用户的Ubuntu 16.04安装机器。
使用RVM安装Ruby on Rails的最简单方法是以非root用户身份运行以下命令,并会提示您输入常规密码。
我们将使用“ gpg”命令联系公共键服务器,并请求给定ID的关联键。
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 Output: gpg: directory `/home/ubuntu/.gnupg' created gpg: new configuration file `/home/ubuntu/.gnupg/gpg.conf' created gpg: WARNING: options in `/home/ubuntu/.gnupg/gpg.conf' are not yet active durin g this run gpg: keyring `/home/ubuntu/.gnupg/secring.gpg' created gpg: keyring `/home/ubuntu/.gnupg/pubring.gpg' created gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net gpg: /home/ubuntu/.gnupg/trustdb.gpg: trustdb created gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported gpg: no ultimately trusted keys found gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1)
现在我们将在/ tmp文件夹中下载RVM脚本
$ cd /tmp
以下是下载用于安装RVM的脚本的命令。
$ \curl -sSL https://get.rvm.io -o rvm.sh
下载脚本后,我们将运行以下命令进行安装,该命令将安装稳定的Rails版本并安装最新的稳定版本的Ruby。
$ cat rvm.sh | bash -s stable --rails Output: Downloading https://github.com/rvm/rvm/archive/1.27.0.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.27.0/1.27.0.tar.gz.asc gpg: Signature made Tuesday 29 March 2016 07:19:47 PM IST using RSA key ID BF04FF17 gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>" 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: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3 Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36 166B E206 C29F BF04 FF17 GPG verified '/home/ubuntu/.rvm/archives/rvm-1.27.0.tgz' Adding rvm PATH line to /home/ubuntu/.profile /home/ubuntu/.mkshrc /home/ubuntu/.bashrc /home/ubuntu/.zshrc. Adding rvm loading line to /home/ubuntu/.profile /home/ubuntu/.bash_profile /home/ubuntu/.zlogin. Installation of RVM in /home/ubuntu/.rvm/ is almost complete: * To start using RVM you need to run `source /home/ubuntu/.rvm/scripts/rvm` in all your open shell windows, in rare cases you need to reopen all shell windows. # ubuntu, # # Thank you for using RVM! # We sincerely hope that RVM helps to make your life easier and more enjoyable!!! # # ~Wayne, Michal & team. In case of problems: https://rvm.io/help and https://twitter.com/rvm_io rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/] Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/16.04/x86_64/ruby-2.3.0.tar.bz2 Checking requirements for ubuntu. Installing requirements for ubuntu. Updating system.... Installing required packages: libsqlite3-dev, sqlite3, libgmp-dev, libtool, pkg-config........ Requirements installation successful. ruby-2.3.0 - #configure ruby-2.3.0 - #download % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 24.8M 100 24.8M 0 0 670k 0 0:00:37 0:00:37 --:--:-- 911k No checksum for downloaded archive, recording checksum in user configuration. ruby-2.3.0 - #validate archive ruby-2.3.0 - #extract ;ruby-2.3.0 - #validate binary ruby-2.3.0 - #setup ruby-2.3.0 - #gemset created /home/ubuntu/.rvm/gems/ruby-2.3.0@global ruby-2.3.0 - #importing gemset /home/ubuntu/.rvm/gemsets/global.gems.............................. ruby-2.3.0 - #generating global wrappers........ ruby-2.3.0 - #gemset created /home/ubuntu/.rvm/gems/ruby-2.3.0 ruby-2.3.0 - #importing gemsetfile /home/ubuntu/.rvm/gemsets/default.gems evaluated to empty gem list ruby-2.3.0 - #generating default wrappers........ Creating alias default for ruby-2.3.0... .. .. Installing ri documentation for rails-5.0.0.1 Done installing documentation for i18n, thread_safe, tzinfo, concurrent-ruby, activesupport, rack, rack-test, mini_portile2, nokogiri, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubis, actionview, actionpack, activemodel, arel, activerecord, globalid, activejob, mime-types-data, mime-types, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, thor, method_source, railties, bundler, sprockets, sprockets-rails, rails after 72 seconds 36 gems installed * To start using RVM you need to run `source /home/ubuntu/.rvm/scripts/rvm` in all your open shell windows, in rare cases you need to reopen all shell windows. * To start using rails you need to run `rails new <project_dir>`.
安装完成后,我们需要运行以下命令以添加环境变量和路径
$ source /home/ubuntu/.rvm/scripts/rvm
现在我们将检查安装,以下是用于检查安装的命令。
$ rvm Output: = rvm * https://rvm.io/ * http s://github.com/rvm/rvm/ == DESCRIPTION: RVM is the Ruby enVironment Manager (rvm). It manages Ruby application environments and enables switching between them. == Installation …… …… Action documentation available with 'rvm help action-name': alias autolibs cleanup config-get cron current debug disk-usage do docs fetch fix-permissions gemdir gemset gemset/copy get group implode info install list migrate mount notes osx-ssl-certs patchset pkg prepare reinstall remove repair requirements reset rubygems rvmrc rvmrc/to rvmrc/warning snapshot srcdir tools uninstall upgrade use user wrapper Other topics of documentation available with 'rvm help topic': alt color upgrade-notes For additional information please visit RVM's documentation website: https://rvm.io/ If you still cannot find an answer to your question, find 'wayneeseguin', 'mpapis', 'richo', 'lemoinem' or 'rys' in #rvm on irc.freenode.net: http://webchat.freenode.net/?channels=rvm
如果我们要安装特定版本的Ruby以满足您的要求,则必须使用以下命令。
列出可用版本
$ rvm list known
要安装特定版本
$ rvm install version_no
列出已安装的版本
$ rvm list
切换到特定的安装版本
$ rvm use ruby_version
由于Rails是gem,因此我们也可以安装特定版本以满足我们的环境,gem是要安装的命令,我们可以使用以下命令来执行安装。
列出Rails的有效版本
$ gem search ‘rails$’ –all
要安装特定版本
$ gem install rails –v version_no
创建宝石集
$ rvm gemset create new_gemset_name
用新的gemset指定Ruby版本。
$ rvm ruby_version@new_gemset_name
由于某些Rails功能取决于JavaScript运行时环境,因此我们需要安装Node.js。
以下是安装Node.js的命令
$ cd /tmp $ \curl -sSL https://deb.nodesource.com/setup_6.x -o nodejs.sh $ less nodejs.sh $ cat /tmp/nodejs.sh | sudo -E bash – Output: ## Installing the NodeSource Node.js v6.x repo... ## Populating apt-get cache... + apt-get update Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease Hit:2 http://deb.kamailio.org/kamailio jessie InRelease Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease Hit:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease Reading package lists... Done W: http://deb.kamailio.org/kamailio/dists/jessie/InRelease: Signature by key E79ACECB87D8DCD23A20AD2FFB40D3E6508EA4C8 uses weak digest algorithm (SHA1) … .. Fetched 6,595 B in 9s (680 B/s) Reading package lists... Done W: http://deb.kamailio.org/kamailio/dists/jessie/InRelease: Signature by key E79ACECB87D8DCD23A20AD2FFB40D3E6508EA4C8 uses weak digest algorithm (SHA1) ## Run `apt-get install nodejs` (as root) to install Node.js v6.x and npm
现在我们可以使用apt-get命令获取Node.js
$ sudo apt-get install nodejs Output: Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: nodejs 0 upgraded, 1 newly installed, 0 to remove and 107 not upgraded. Need to get 10.1 MB of archives. After this operation, 50.7 MB of additional disk space will be used. Get:1 https://deb.nodesource.com/node_6.x xenial/main amd64 nodejs amd64 6.8.1-1nodesource1~xenial1 [10.1 MB] Fetched 10.1 MB in 37s (272 kB/s) Selecting previously unselected package nodejs. (Reading database ... 70921 files and directories currently installed.) Preparing to unpack .../nodejs_6.8.1-1nodesource1~xenial1_amd64.deb ... Unpacking nodejs (6.8.1-1nodesource1~xenial1) ... Processing triggers for man-db (2.7.5-1) ... Setting up nodejs (6.8.1-1nodesource1~xenial1) ...
在本文结束之后,您将能够通过具有多个Ruby环境的JavaScript运行时来设置和配置RVM以安装Ruby和Rails。