This beginner's guide will set up with Ruby 1.9.2, RVM and Rails 3.0.3 and is specifically written for a development environment on Ubuntu 10.10, but will probably work on many other operating systems, including older versions of Ubuntu and Debian. YMMV.
If you're looking for a way to set this up on a production server then I would recommend the use of the railsready script which installs all the necessary packages for Ruby 1.9.2p136 and then that version of Ruby itself, Bundler and Rails. Then it leaves it up to you to install Apache or nginx to get your application online.
If you're not using Ubuntu then try Wayne E. Seguin's rails_bootstrap_script which probably gets a version of Rails working for you, albeit with 1.8.7 rather than 1.9.2.
Under no circumstance should you install Ruby, Rubygems or any Ruby-related packages from apt-get. This system is out-dated and leads to major headaches. Avoid it for Ruby-related packages. We do Ruby, we know what's best. Trust us.
Still not convinced? Read this.
This guide will go through installing the RVM (Ruby Version Manager), then a version of Ruby (1.9.2), then Rails and finally Bundler.
By the end of this guide, you will have these things installed and have some very, very easy ways to manage gem dependencies for your different applications / libraries, as well as having multiple Ruby versions installed and usable all at once.
We assume you have sudo access to your machine, and that you have an understanding of the basic concepts of Ruby, such as “What is Rubygems?” and more importantly “How do I turn this computer-thing on?”. This knowledge can be garnered by reading the first chapter of any Ruby book.
Housekeeping
First of all, we’re going to run sudo apt-get update so that we have the latest sources on our box so that we don’t run into any package-related issues, such as not being able to install some packages.
Next, we’re going to install Git (a version control system) and curl which are both required to install and use RVM, and build-essential which is required to compile Ruby versions, amongst other compilable things. To install these three packages we use this command:
sudo apt-get install build-essential git-core curl
RVM
RVM is a Ruby Version Manager created by Wayne E. Seguin and is extremely helpful for installing and managing many different versions of Ruby all at once. Sometimes you could be working on a project that requires an older (1.8.7) version of Ruby but also need a new version (1.9.2) for one of your newer projects. This is a problem that RVM solves beautifully.
Another situation could be that you want to have different sets of gems on the same version of Ruby but don’t want to have to do deal with Gem Conflict Hell. RVM has gemsets for this. This is a feature you wouldn't have if you used the packaged Ruby.
We’re going to use it to install only one version of Ruby, but we can consult the documentation if we want to install a different version of Ruby.
With git-core and curl installed we’ll be able to install RVM with this command:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
The beautiful part of this is that it installs Ruby to our home directory, providing a sandboxed environment just for us.
Once that’s done, we’re going to need to add a line to ~/.bashrc file (the file responsible for setting up our bash session) which will load RVM:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
Then we’ll need to reload the ~/.bashrc file which we can do with this small command:
. ~/.bashrc
The next command we run will tell us what other packages we need to install for Ruby to work:
rvm notes
...
# For Ruby (MRI & ree) you should install the following OS dependencies:
ruby: aptitude install build-essential bison openssl libreadline6 libreadline6-dev
curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0
libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf
A couple of these packages we’ve already installed, such as git-core and curl. They won’t be re-installed again.
These packages will lessen the pain when we’re working with Ruby. For example, the libssl-dev package will make OpenSSL support in Ruby work, libsqlite3-0 and libsqlite3-dev are required for the sqlite3-ruby gem and the libxml2-dev and libxslt-dev packages are required for the nokogiri gem. Let’s install all these packages now using this command:
sudo aptitude install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g
zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf
This command *must* be written on a single line, otherwise some of the packages will not install.
Now our Ruby lives will be as painless as possible.
Ruby
With RVM and these packages we can install Ruby 1.9.2:
rvm install 1.9.2
This command will take a couple of minutes, so grab your $DRINKOFCHOICE and go outside or something. Once it’s done, we’ll have Ruby 1.9.2 installed. To begin using it we can use this lovely command:
rvm use 1.9.2
Are we using 1.9.2? You betcha:
ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
Or, even better, would be to make this the default for our user! Oooh, yes!
rvm --default use 1.9.2
Now whenever we open a new bash session for this user we’ll have Ruby available for us to use! Yay!
Rails
Now that RVM and a version of Ruby is installed, we can install Rails. Because RVM is installed to our home directory, we don’t need to use that nasty sudo to install things; we’ve got write-access! To install the Rails gem we’ll run this command:
gem install rails
This will install the rails gem and the other 22 gems that it and its dependencies depend on, including Bundler.
MySQL
If you’re planning on using the mysql2 gem for your application then you’ll want to install the libmysqlclient16-dev package before you do that. Without it, you’ll get an error when the gem tries to compile its native extensions:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/home/ryan/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
PostgreSQL
Similar to the mysql2 gem’s error above, you’ll also get an error with the pg gem if you don’t have the libpq-dev package installed you’ll get this error:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/ryan/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for pg_config... no
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Fin.
And that’s it! Now you’ve got a Ruby environment you can use to write your (first?) Rails application in with such minimal effort. A good read after this would be the official guides for Ruby on Rails. Or perhaps the documentation on the RVM site which goes into using things such as gemsets and the exceptionally helpful per-project .rvmrc file. A quick way to generate an .rvmrc file is to run a command like this inside the project
rvm use 1.9.2@rails3 --rvmrc
RVM is such a powerful tool and comes in handy for day-to-day Ruby development. Use it, and not the packages from apt to live a life of development luxury.
分享到:
相关推荐
Ruby on Rails is the revolutionary online programming tool that makes creating functional e-commerce web sites faster and easier than ever. With the intuitive, straightforward nature of Ruby and the ...
标题与描述均提到了“ruby on rails安装环境”,这表明文档主要关注的是如何在特定的环境中设置Ruby on Rails。Ruby on Rails(常简称为Rails)是一种用于开发Web应用程序的开源框架,采用Ruby语言编写,遵循MVC...
Ubuntu用户通常会依赖于包管理工具`apt-get`来安装Ruby,这种方式虽然简单便捷,但在某些情况下可能无法满足定制化的需求。本文将详细介绍如何通过手动编译的方式安装Ruby,并提供一种灵活的升级策略。 #### 手动...
### 安装STLinux在Ubuntu上的关键步骤与挑战 #### 概览 本文将深入探讨在Ubuntu上安装STLinux的全过程,重点解析由于包管理系统的差异而带来的挑战及其解决方案。对于那些希望在Ubuntu环境中利用STLinux强大功能的...
但在此之前,如果你遇到了“Error installing redis: redis requires Ruby version >= 2.3.0”的错误,这意味着Redis需要一个更高版本的Ruby才能安装。在安装Redis之前,请确保你的Ruby版本至少是2.3.0,如果尚未...
面是我在Ubuntu6.06 LTS 下源码编译安装samba主要安装过程,本人第一次用Ubuntu,刚装上去时候,没有gcc编译环境。郁闷了半天。找出这一过程发了不少的时间。可能还有些不妥,不过我经过这样的安装达到了向windows共享...
OpenERP Installing Ubuntu9.04
### 安装Anaconda在Ubuntu上的详细步骤及关键知识点 #### 一、Anaconda简介 Anaconda是一款非常受欢迎的数据科学平台,它集成了Python或R语言环境中的许多库和工具,便于用户进行数据处理、科学计算、机器学习等...
Installing Your Driver on Windows Millennium INF File Guide
- Installing Rails on Windows requires setting up Ruby, installing gems like `bundler`, and configuring the environment. Developers often use tools like RubyInstaller and DevKit for Windows. 2. **...
# SAP Ruby on Rails with AJAX: An In-depth Exploration ## Introduction The integration of SAP and Ruby on Rails has sparked considerable interest in the IT community, leading to the development of ...
Auth0 + Ruby on Rails WebApp种子+示例 该项目的目标是帮助将Auth0功能集成到Ruby on Rails应用程序中。 您可以在了解有关种子项目和示例的更多信息。 解决问题 如果在Mac上收到以下错误,请执行以下操作: An ...
Many former Java developers still use Ruby on Rails today, the most popular framework for building Ruby applications. What You'll Learn What are the fundamentals of Ruby and its object-oriented ...
Installing Ubuntu—Getting started 11 Finishing Installation 16 2 The Ubuntu Desktop 19 Understanding the Ubuntu desktop 19 Unity 19 The Launcher 21 The Dash 21 Workspaces 24 Managing windows 24 Unity...
### 安装Activ Test软件至个人电脑的知识点详解 #### 一、背景介绍 随着信息技术的发展,越来越多的专业技能认证考试采用计算机化的方式进行。其中,ECDL(欧洲计算机驾驶执照)作为一项广泛认可的计算机操作技能...
Installing Ubuntu 14.04 & ROS & TurtleBot 06-29-2016 个人小结,关于Ubuntu和ROS的安装。
从压缩包文件`Installing Oracle9i on RedHat Linux 7_2, 7_3, 8_0, 9, AS 2_1, 3_0 (Red Hat Enterprise Advanced Server 3 - RHEL AS 3) (Oracle database installation, install Oracle software).htm`中,我们...
在 Windows 平台上进行 Ruby on Rails 开发时,可能会遇到各种各样的安装问题。本文将详细解释一个常见的问题:“在 Windows 下安装或升级 Rails 时,gem 命令提示需要更新 PATH 或下载 DevKit”,并提供详细的解决...