Ruby on rails actual Bible: install the Rails development environment

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Install the Rails development environment Give someone aprogram, you frustrate them for a day; teach them how to program, you frustratethem for a lifetime. - David Leinweber
In this chapter, we will introduce how to install the Rubyon Rails development environment. Rails development environment:
· Ruby 1.8.7, The above 1.9.2 or JRuby, the book uses 1.9.3.
· RubyGems, This is a suite of management system of Ruby, the book recommended version 1.3.7 or above 1.8.10.
· The database system, this book is recommended to use the SQLite as a new development exercises with, formal environment like MySQL or PostgreSQL.
· Ruby on Rails, This book is the 3.2 Edition.
Please note that Rails 3 does not support this version of Ruby 1.9.1.
The code to deal with, is the Ruby series 1.9 and previous versions of the biggest differences such as: if UTF-8 Chinese appear original code, the first line of the file must be added # encoding: UTF-8 marked, otherwise there will be a invalid multibyte char (US-ASCII) error, to pay particular attention to this point.
The difference between JRuby and Ruby is the largest number of need to compile the RubyGem Suite: some because the performance requirements and use of the C language to write the RubyGem in the JRuby may not be able to install and use. Fortunately, these generally have alternative kit can be used, but not in the scope of the book describes.
The above is about the most basic development needs. If you need to deploy to the formal environment, you need at least a dedicated web server (Apache or Nginx), we will in the deployment of a chapter more detailed description. Next we will according to the different operating system to explain how to use the Rails development environment.

Operating system


Ruby can run on Windows, Linux, Mac OS X, BSD and Solaris. Although the Rails can be executed on a Windows, but some suite only support Unix-like operating system, as well as the Ruby program in Unix-like system implementation is also relatively fast and stable. This is because most Ruby and Rails developers are using Mac and Linux system.
Unix Unix-like refers to a variety of traditional, such as FreeBSD, OpenBSD, Solaris, and various system similar to Unix, such as Linux, Mac OS X etc.. Some free software, some commercial software, but are mostly retained the characteristics of original Unix system, and there are many similarities.
Therefore, will strongly recommend the use of Unix-like operating system Rails officially launched environment. As a developer, has a good user interface, the underlying Mac operating system and Unix like becomes the preferred development platform, most of the professional Ruby workers, are also using the Mac computer. However, the use of Windows friends and don't worry, the contents of this book are suitable for entry learning, absolutely no problem. Only if the reader daily work is Web website development, then I would suggest that you consider using the Mac system or try Ubuntu Desktop operating system. As with Ruby, the conversion from Windows to Mac is also very interesting things, have a lot of fun.
This is the use of open source software need to be considered: open source software is to rely on the community to maintain, so more people use the mainstream platform (operating system, database etc.) will support better, and fewer people with platform can mine more.

Database


Rails supported databases include SQLite3, MySQL, Postgres, IBM, DB2, Oracle and SQLServer etc.. In addition to install database software, Ruby library we also need to install the collocation (known as Adapter or Driver). As a new single exercise, you can use SQLite, the Zhang Huixian SQLite installation way. Appendix will introduce how to install MySQL and PostgreSQL.

Development environment


The command line window

There are many tasks need through the command line interface (CommandLine Interface), like the installation package, execute the rails command, execute test etc.. Although there are some GUI graphical interface tool can help, but in the end you'll find out or directly on the command line input the fastest and most reliable when problems occur, also easy to debug.
Mac OS to enter the command line window, open the Go-> Utilities Terminal, or the author recommended to installiTerm. Ubuntu Desktop Applications-> Accessories Terminal. Windows is the "start -> Affiliate application" in "command prompt」.
The Unix-like instruction and Windows instruction are different, the following are some commonly used commands:
Use
Unix-like
Windows
Mobile directory
cd XXX
cd XXX
Moving to a directory
cd ..
cd ..
Display the current directory
pwd
cd
Display the current directory file
ls
dir
Delete files
rm XXX
erase XXX
Delete directory
rmdir XXX
rmdir XXX
Create a directory
mkdir XXX
mkdir XXX
In addition, in the input file name or directory name, can be completed automatically by tab.

Software development

Before starting to write the program, let us first introduce what's recommended editor. Compared with the static language such as C++, Java like feature rich IDE (IntegratedDevelopment Environment) software, dynamic languages, although there are also some IDE software, but more and more people prefer a simple text editor (Editor) and the command line window can play all over the world. This is because the dynamic expression of language ability strong, automatically generated code, compiler, IDE provides sophisticated browsing and so on are not so need.
The Editor text editor
· Textmate (Mac OS platform)
· Notepad++ (Windows platform)
· SublimeText http://www.sublimetext.com (Windows, Linux, Mac platform)
· Vim
· Emacs http://www.gnu.org/software/emacs/
IDE software
· JetBrainsRubyMine
· AptanaRedRails
No matter what the editor, please note that the file format to store UTF-8, no BOM (byte-order mark) meter.

The version control system

The version control system can save all changes in procedures, records who changed what, at what time, what reason is because, collaborative team development indispensable tool. Git is a set of distributed version control systems generally use the Ruby community. Although not necessary to learn Git learning Rails, but since Rails itself and most of the suite are using the Git version control system, and put inGitHubOn the. So you'd better have Git installed and learn the basic operation. Introduction about the Git please refer to Appendix.

The installation of Ruby and database


The following is respectively in Windows, Mac OSX, Ubuntu Desktop operating system, the most convenient way to install Ruby. After development started Rails, can refer to appendix, in accordance with the demand for the installation of different development environment.

Windows

Developed in the Windows Rails is the fastest way to download the RailsInstaller installation package, which includes Ruby 1.9.3, Rails 3.2, SQLite 3, Git version control system and SQL Server Adapter. Can let you start Rails in the installation for a short period of time.
Using the Git version control system, please refer to Appendix.

Mac OS X

In order to successfully install some need to compile the suite, you must first install Xcode. XCode 4.3 version, also have to manually install Command Line Tools, menu > from your Xcode; Preferences > Downloads to enter setup.
The following installationHomebrewTo manage the MacOS package, which can be convenient to install some software tools used, such as Git, MySQL, SQLite, even Memcached, Sphinx, Redis, MongoDB and so on can be through the Homebrew installation. The book of Mac installation steps can use Homebrew, it is to carry out the installation steps:
$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
Homebrew is also using Ruby program language. Another old package management tools is MacPort.
SnowLeopard and Lion built-in Ruby 1.8.7, so here through the Homebrew to install the new Ruby 1.9.3, Git, SQLite:
$ brew install git
$ brew install sqlite
$ brew install ruby
Enter the following command to join PATH (different versions of the Ruby path will be different, please install brew after install Ruby prompt):
$ echo 'export PATH=/usr/local/Cellar/ruby/1.9.3-p327/bin:$PATH' >> ~/.bash_profile
$ export PATH=/usr/local/Cellar/ruby/1.9.3-p327/bin:$PATH
After the completion of input the following instructions can see the installed version:
$ git --version
git version 1.8.0.2
$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.1]

Linux(Ubuntu 10.04 LTS)

Firstly, the Linux update:
$ sudo apt-get update
$ sudo apt-get upgrade
Install the necessary Kit:
$ sudo apt-get 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 libc6-dev
Then download the Ruby source code compiler, please refer to the Ruby website to download the latest version 1.9:
$ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
$ tar xvfz ruby-1.9.3-p327.tar.gz
$ cd ruby-1.9.3-p327/
$ ./configure
$ make
$ sudo make install
After the completion of input the following instructions can see the installed version:
$ git --version
git version 1.7.0.4
$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
SQLite Manager is a Firefox plugin GUI interface SQLite, can be used to facilitate the examination of the contents of the database.
Chinese version of Ubuntu's default apt-get suite server tw.archive.ubuntu.com sometimes not very steady, if necessary, you can change the /etc/apt/sources.list into debian.nctu.edu.tw or archive.ubuntu.com.

Introduction to RubyGems


RubyGems is a suite of Ruby management system, allows you to easily install and manage Ruby library. You can find all the Ruby open source suite in RubyGems. In addition, if you want to find Ruby or Rails are some of the useful kit, also can browse The Ruby Toolbox have a look, this station in accordance with the hot degree suite sort, very convenient.

Commonly used commands

gem -v To tell you RubyGems Edition
gem update --system UpgradeRubyGemsEdition
gem install gem_name Install a package
gem list A list of installed Suite
gem update gem_name Updated to the latest version
gem update Update all of your installedGems
gem install -v x.x.x gemname Install a specific version
gem uninstall gem_name Anti.Loading
Implementation of gem install gem_name, it will be in after installation, automatic generation of the suite of the RDoc and RI files. But in view of the current network developed, often directly to Google or is in, and you can query to a file, so I really don't need to produce documents in the local machine, and installation time consuming and total hard disk space. To omit this step, there are two ways:
Every time when installed, plus the following parameters:
$ gem install gem_name --no-ri --no-rdoc
Or a new ~/.gemrc file as follows, the default will not produce documents:
gem: --no-ri --no-rdoc
Linux users need to add sudo, such as sudo gem install gemname.

The installation of Ruby on Rails


The first is SQLite Adapter:
$ gem install sqlite3 --no-ri --no-rdoc
The last is the installation of Rails.:
$ gem install rails --no-ri --no-rdoc
After the completion of the input rails-v, you should see Rails 3.2.1.
Ubuntu needs to install packages root permissions: sudo gem install rails
In order to save installation time can not install files, plus the --no-ri and --no-rdoc parameters.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Griffith at January 06, 2014 - 8:53 PM