在本文中,我们将学习如何设置和配置Ruby on Rails,它是开发人员用来创建站点和Web应用程序的最流行的堆栈应用程序。Ruby是一种编程语言,程序员可以将它与Rails开发框架结合使用,以使应用程序开发变得快速而简单。
“ rbenv”是用于安装Ruby和Rails的命令行工具,它也为使用Ruby on Rails进行应用程序开发提供了良好的环境。“ rbenv”提供特定于应用程序的Ruby版本。
我们需要具有非root用户的Ubuntu 16.04安装机器。
在开始安装之前,我们需要更新和安装所有相关的依赖项。
首先,我们将更新Ubuntu,要更新Ubuntu,我们需要运行以下命令。
$ sudo apt-get update
然后,我们将使用apt-get安装rbenv和Ruby所需的所有依赖项,下面是安装依赖项的命令。
$ sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev Output: Reading package lists... Done Building dependency tree Reading state information... Done build-essential is already the newest version (12.1ubuntu2). build-essential set to manually installed. libgdbm3 is already the newest version (1.8.3-13.1). libgdbm3 set to manually installed. The following additional packages will be installed: automake libbison-dev libssl-doc libssl1.0.0 libtinfo-dev libyaml-0-2 m4 Suggested packages: autoconf-archive gnu-standards autoconf-doc libtool bison-doc ncurses-doc readline-doc libyaml-doc The following NEW packages will be installed: autoconf automake bison libbison-dev libffi-dev libgdbm-dev libncurses5-dev libreadline6-dev libssl-dev libssl-doc libtinfo-dev libyaml-0-2 libyaml-dev m4 zlib1g-dev The following packages will be upgraded: libssl1.0.0 1 upgraded, 15 newly installed, 0 to remove and 107 not upgraded. Need to get 4,888 kB/5,970 kB of archives. After this operation, 19.1 MB of additional disk space will be used. Do you want to continue? [Y/n] y …. …. Setting up libyaml-0-2:amd64 (0.1.6-3) ... Setting up libssl1.0.0:amd64 (1.0.2g-1ubuntu4.5) ... Setting up m4 (1.4.17-5) ... Setting up autoconf (2.69-9) ... Setting up automake (1:1.15-4ubuntu1) ... update-alternatives: using /usr/bin/automake-1.15 to provide /usr/bin/automake (automake) in auto mode Setting up libbison-dev:amd64 (2:3.0.4.dfsg-1) ... Setting up bison (2:3.0.4.dfsg-1) ... update-alternatives: using /usr/bin/bison.yacc to provide /usr/bin/yacc (yacc) in auto mode Setting up libgdbm-dev (1.8.3-13.1) ... Setting up libtinfo-dev:amd64 (6.0+20160213-1ubuntu1) ... Setting up libncurses5-dev:amd64 (6.0+20160213-1ubuntu1) ... Setting up libreadline6-dev:amd64 (6.3-8ubuntu2) ... Setting up zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4) ... Setting up libssl-dev:amd64 (1.0.2g-1ubuntu4.5) ... Setting up libssl-doc (1.0.2g-1ubuntu4.5) ... Setting up libffi-dev:amd64 (3.2.1-4) ... Setting up libyaml-dev:amd64 (0.1.6-3) ... Processing triggers for libc-bin (2.23-0ubuntu3) ...
我们将使用git存储库安装“ rbenv”,要安装或获取rbenv,我们必须运行以下命令。
$ git clone https://github.com/rbenv/rbenv.git /opt/.rbenv Cloning into '/root/.rbenv'... remote: Counting objects: 2542, done. remote: Total 2542 (delta 0), reused 0 (delta 0), pack-reused 2542 Receiving objects: 100% (2542/2542), 461.53 KiB | 120.00 KiB/s, done. Resolving deltas: 100% (1597/1597), done. Checking connectivity... done.
我们必须将/opt/.rbenv添加到$PATH中,以便可以使用rbenv将所需的环境路径添加到〜/ .bash_profile文件中。
要添加环境变量并启动“ rbenv”,我们需要添加以下几行,还添加源rbenv
$ echo 'export PATH="/opt/.rbenv/bin:$PATH"' >> ~/.bashrc $ echo 'eval "$(rbenv init -)"' >> ~/.bashrc $ source ~/.bashr
现在,我们将检查rbenv,以检查rbenv是否正常工作,以便我们可以运行以下命令–
$ type rbenv Output: rbenv is a function rbenv () { local command; command="$1"; if [ "$#" -gt 0 ]; then shift; fi; case "$command" in rehash | shell) eval "$(rbenv "sh-$command" "$@")" ;; *) command rbenv "$command" "$@" ;; esac }
要使用rebenv,请安装命令,该命令可使Ruby的安装过程更加简单。我们应该安装ruby-build,它将作为rbenv的插件安装,我们将使用以下命令从git存储库获取插件。
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build Cloning into '/root/.rbenv/plugins/ruby-build'... remote: Counting objects: 6981, done. remote: Total 6981 (delta 0), reused 0 (delta 0), pack-reused 6981 Receiving objects: 100% (6981/6981), 1.35 MiB | 182.00 KiB/s, done. Resolving deltas: 100% (4151/4151), done. Checking connectivity... done.
我们将使用rbenv插件ruby-build来安装Ruby,我们需要运行以下命令以列出Ruby的所有可用版本。其中显示了可用版本的一长串。
$ rbenv install –l Output: Available versions: 1.8.5-p113 1.8.5-p114 1.8.5-p115 1.8.5-p231 1.8.5-p52 1.8.6-p110 1.8.6-p111 1.8.6-p114 1.8.6-p230 …. … rbx-3.56 rbx-3.57 rbx-3.58 rbx-3.59 rbx-3.60 ree-1.8.7-2011.03 ree-1.8.7-2011.12 ree-1.8.7-2012.01 ree-1.8.7-2012.02 topaz-dev
我们将仅安装特定版本。例如,如果要安装Ruby版本2.3.1,则可以使用global命令将其设置为默认版本。
$ sudo rbenv install 2.3.1 Output: Downloading ruby-2.3.1.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.bz2 Installing ruby-2.3.1... Installed ruby-2.3.1 to /root/.rbenv/versions/2.3.1 $ sudo rbenv global 2.3.1
通过运行简单的命令rbenv install 2.3.0,我们也可以具有不同的版本。安装软件后,我们将使用以下命令验证ruby的安装–
$ ruby –v Output: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
Gem是将被安装以扩展Ruby功能的软件包。我们必须使用gem命令安装软件包。我们将使用带有gem的install命令来安装依赖项。
$ echo "gem: --no-document" > ~/.gemrc $ gem install bundler Output: Fetching: bundler-1.13.5.gem (100%) Successfully installed bundler-1.13.5 1 gem installed
现在,我们将使用gem env命令来了解有关环境和gem配置的更多信息,我们可以通过使用home参数检查gem安装位置,该参数将显示服务器上安装的gem的路径。
$ gem env home Output: /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
现在,我们将使用gem install命令安装最新版本的Rails。以下是安装滑轨的命令–
$ gem install rails Output: Successfully installed bundler-1.13.5 1 gem installed root@ubuntu-16:~# gem env home /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0 $ gem install rails Fetching: i18n-0.7.0.gem (100%) Successfully installed i18n-0.7.0 Fetching: thread_safe-0.3.5.gem (100%) Successfully installed thread_safe-0.3.5 Fetching: tzinfo-1.2.2.gem (100%) Successfully installed tzinfo-1.2.2 Fetching: concurrent-ruby-1.0.2.gem (100%) Successfully installed concurrent-ruby-1.0.2 Fetching: activesupport-5.0.0.1.gem (100%) Successfully installed activesupport-5.0.0.1 Fetching: rack-2.0.1.gem (100%) Successfully installed rack-2.0.1 Fetching: rack-test-0.6.3.gem (100%) Successfully installed rack-test-0.6.3 Fetching: mini_portile2-2.1.0.gem (100%) Successfully installed mini_portile2-2.1.0 Fetching: nokogiri-1.6.8.1.gem (100%) Building native extensions. This could take a while... … …. … Successfully installed websocket-driver-0.6.4 Fetching: actioncable-5.0.0.1.gem (100%) Successfully installed actioncable-5.0.0.1 Fetching: thor-0.19.1.gem (100%) Successfully installed thor-0.19.1 Fetching: method_source-0.8.2.gem (100%) Successfully installed method_source-0.8.2 Fetching: railties-5.0.0.1.gem (100%) Successfully installed railties-5.0.0.1 Fetching: sprockets-3.7.0.gem (100%) Successfully installed sprockets-3.7.0 Fetching: sprockets-rails-3.2.0.gem (100%) Successfully installed sprockets-rails-3.2.0 Fetching: rails-5.0.0.1.gem (100%) Successfully installed rails-5.0.0.1
安装软件包后,我们将验证Rails的正确安装,我们需要运行以下命令。
$ rails –v Output: Rails 5.0.0.1
由于某些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 – cat /tmp/nodejs.sh | sudo -E bash - ## 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 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) ...
在以上文章中,我们了解了安装“ rbenv”的基本知识,即Ruby on Rails,我们可以设置多个Ruby环境。
本文向大家介绍如何在Ubuntu 16.04上使用'RVM'设置和配置Ruby on Rails,包括了如何在Ubuntu 16.04上使用'RVM'设置和配置Ruby on Rails的使用技巧和注意事项,需要的朋友参考一下 在本文中,我们将学习如何设置和配置Ruby on Rails,它是开发人员使用的最流行的堆栈应用程序,通常用于创建站点和Web应用程序。Ruby是一种编程语言,程序员可以结
我在使用appium运行java mobile automation测试用例时遇到了这个错误 处理命令时发生未知的服务器端错误。原始错误:packageAndLaunchActivityFromManifest失败。原始错误:找不到aapt请用Android SDK根目录路径设置ANDROID_HOME环境变量。(警告:服务器未提供任何stacktrace信息) 配置: IntelliJ IDE-
但是如果我让Spring Boot自动配置JOOQ,那么我应该把这个设置放在哪里呢? 基本的Spring Boot配置似乎只支持在中设置,如jooq-spring-boot-example所示。 我尝试将放入中,但这对SQL没有任何影响。 有没有办法自定义Spring boot JOOQ配置,而不必自己配置JOOQ? 我使用的是SpringBoot 2.1.7.Release和JOOQ 3.11.
我有两个环境来设置我的API,所以我有生产和开发。我首先需要的是找到一种方法来自动完成这一任务,例如,在运行时,不发送任何参数(-d)应用程序找到了一种方法来识别环境,但我没有找到任何方法来完成这一任务。 所以我看了一个教程,在同样有一个方法放了一个环境变量,并定义了我的application.properties。所以在下面的步骤中: > 我在我的应用程序中定义了3个文件,application
本文向大家介绍如何在Ubuntu 16.04上设置和配置Jekyll开发站点,包括了如何在Ubuntu 16.04上设置和配置Jekyll开发站点的使用技巧和注意事项,需要的朋友参考一下 在本文中,我们将学习如何设置和配置Jekyll开发站点。Jekyll在数据库驱动的站点中提供了内容管理系统(CMS)的优势,并具有性能和安全性。它也称为博客意识,具有处理按日期组织的内容的功能。它特别适合于离线工
问题内容: 我想使用带有以下条目的application.properties文件设置配置文件: 如何在我的context.xml文件中设置spring.profiles.active?init-param仅在web.xml上下文中有效。 问题答案: 有几种更改活动配置文件的方法,这些方法都不直接取自属性文件。 您可以像在问题中一样使用。 您可以在应用程序启动时提供系统参数 你可以得到从你和编程方