Install Rails to develop the environment
Give someone a program, your frustrate them for a day; Teach them how to program, you frustrate them for a lifetime. -David Leinweber
Https://ihower.tw/rails4/installation.html
In this chapter, we will introduce how to install Ruby on rails in the development environment. Developing the rails environment requires:
- Ruby 1.9.3 or above version or JRuby, this book uses 2.1.5.
- The library system, rails presets use SQLite as a beginner to practice, and a formal online environment is recommended for MySQL or PostgreSQL.
- Ruby on Rails, this book is available in version 4.2.
The biggest difference between JRuby and Ruby is in some rubygem kits that need to be translated: some rubygem written in C for performance requirements are not necessarily installed on JRuby. Fortunately, most of these have alternative packages available, but not in this book.
These are almost the most basic development requirements. If you need to deploy to a formal environment, you need at least one Web site server (apache or nginx, etc.), and we'll explain it in a chapter. Next, we'll take a different operating system to explain how to install rails.
Operating system
Ruby works on Windows, Linux, Mac OS X, BSD, and Solaris. While rails can be executed on Windows, some packages only support the Unix-like operating system, and Ruby programs are faster and more stable to perform on the unix-like system. This is because most of the ruby and rails developers are using Mac and Linux systems.
Unix-like refers to a variety of traditional UNIX systems, such as FreeBSD, OpenBSD, Solaris, and Unix-like systems such as Linux, Mac OS x, and so on. Some are free software, some are commercial software, but they all retain the characteristics of the original UNIX system, and there are many similarities.
As a result, the Unix-like operating system is strongly recommended in the formal online environment of rails. As developers, having a good user interface, a bottom layer, and a UNIX-like Mac operating system became the starting platform for the first choice, and most of the professional Ruby workers were using Mac computers. Still, friends who use Windows are not worried, the content of this book is all right, and it's absolutely no problem to learn. Just if the reader's daily job is to go to the Web site, then I would recommend that you consider using the Mac OS system or try the Ubuntu desktop system. As with learning Ruby, switching from Windows to Mac is also a very interesting thing to do and get a lot of fun.
This is a factor to consider when using the source software: The source software is protected by the community, so more people use the mainstream platform (operating system, library, etc.) will support better, and the less people use the platform will be more landmines.
Information repository
Rails supported repositories include SQLite3, MySQL, Postgres, IBM DB2, Oracle, and SQL Server. In addition to the installation information repository, we also need to install a Ruby library (called adapter or driver). As a beginner's machine, you can use SQLite to get started, and this chapter will introduce SQLite's installation style. The attached section will introduce how to install MySQL and PostgreSQL.
Develop an environmental command window
There is a lot of work that needs to be done via the command commandline CLI (command line Interface), such as an installation kit, a rails command, a test, and so on. While there are some GUI graphics interface tools that can help, you'll find it easy to get to the top of the line when it comes to the fastest, most reliable, and problematic time.
Mac OS to enter the command window, please open the go->utilities in the terminal, or the pen is recommended to install ITERM2. Under Ubuntu Desktop is applications->accessories under the terminal. Windows is "command prompt characters" in "Start-to-attach applications".
The instructions of unix-like and the instructions of windows are many different, and the following are some common directives:
Use |
Unix-like |
Windows |
Move your account |
CD XXX |
CD XXX |
Move to the previous category |
Cd.. |
Cd.. |
Show the current location of the catalogue |
Pwd |
Cd |
Showing the files at the moment |
Ls |
Dir |
Delete Files |
RM XXX |
Erase XXX |
Delete a catalogue |
RmDir XXX |
RmDir XXX |
Create a catalogue |
mkdir XXX |
mkdir XXX |
In addition, when you enter a file name or a name, you can press TAB to do it yourself.
Without familiarity with the CLI, it is suggested that you can read the designer's Guide to the OSX command prompt and the command line Crash course.
Develop software
Before you start to write a program, let's introduce some recommended editors. Compared to static languages such as C + +, Java likes the Rich IDE (Integrated development environment) software, there are also some IDE software, but more people prefer simple text editor (editor). With the command window, you can play all over the world. This is because of the strong language of speech, the IDE provides the self-generated code, the editing program, the complex browser feature, and so on is not necessary.
Editor Text editor
- Sublime Text (Windows, Linux, Mac platforms)
- notepad++ (Windows platform)
- Vim
- Emacs
IDE Software
Regardless of the editor, please note that the format of the file should be stored as a UTF-8, no BOM (byte-order Mark) table.
Version control system
The version control system can save all of the program changes, recording who changed what, at what time, because why, is the team to develop an indispensable tool. The Ruby community generally uses this distributed version control system of Git. While learning rails doesn't have to learn git, it's because rails itself, and most of the related packages, are using GIT version control systems and put them on GitHub. So you'd better install git and learn basic things. For Git, please refer to the attached catalogue.
Install Ruby and repositories
Here are some of the fastest and most convenient ways to install Ruby on Mac OSX and Ubuntu desktop systems. After you have started the development of rails, you can refer to the attached records and install them in different environments.
Mac OS X Yosemite (10.10)
We use the Homebrew tool to manage the suite on MacOS, which makes it easy to install common tools such as Git, MySQL, and even memcached, Elasticsearch, Redis, MongoDB and so on can be installed through homebrew. The homebrew is used in the Mac installation step of this book, and its installation step is to perform:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The process will jump out of a window asking if you want to install Xcode's command line tools, please select Install. After completion, return to the command line to continue the homebrew installation.
Mac OS is built with Ruby, but it's an older version, and we've passed homebrew's latest version of Ruby:
$ brew install ruby
After completion, enter the following command to see the installed version:
$ ruby -vruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin13.0]
Linux (Ubuntu Desktop 14.04 LTS)
Start with the Linux update:
$ sudo apt-get update$ sudo apt-get upgrade
Install the necessary kits:
$ 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
Next to download the Ruby source code, please refer to the Ruby official Web download the latest 2.1. Version 5:
$ wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz$ tar xvfz ruby-2.1.5.tar.gz$ cd ruby-2.1.5/$ ./configure$ make$ sudo make install
After the installation is complete, enter the following command to see the installed version:
$ git --versiongit version 2.2.1$ ruby -vruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin13.0]
SQLite Manager is a set of GUI interface for Firefox plugin that provides SQLite, which can be used to easily check the contents of the repository.
The Chinese version of Ubuntu preset Apt-get Kit Server tw.archive.ubuntu.com sometimes not very stable, if necessary, you can modify the/etc/apt/ Sources.list into debian.nctu.edu.tw or archive.ubuntu.com.
Windows 7
Please download the Ruby 2.1.5 package to Rubyinstaller if Windows 7 is a 64-bit download of Ruby 2.1.5 (x64). In the installation process, click Add Ruby to the available path (add Ruby executables to your path).
After the installation is successful, open the "command prompt character" of the "attached application" and enter the following instructions to see the installed version:
$ ruby -vruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32]
In addition, there are some rubygems kits that need to be translated, so you need to development kit. Please download Devkit-mingw64-32-4.7.2-20130224-1151-sfx.exe or 64-bit devkit-mingw64-64-4.7.2-20130224-1432-sfx.exe, and decompress on C \ Under Devkit, enter this in the command prompt character and enter the following command:
$ cd C:\DevKit$ ruby dk.rb init$ ruby dk.rb install
Another way to do this in Windows is by using virtual machines, such as using VirtualBox to run Ubuntu Desktop Edition, or using Cygwin to provide a unix-like environment. So you can avoid the mines on Windows.
RubyGems-A simple introduction
RubyGems is a ruby Suite management system that allows you to easily install and manage Ruby Library. You can find all the Ruby source kits on the RubyGems. Also, if you're looking for useful packages for Ruby or rails, you can browse the Ruby Toolbox and it's easy to sort by the suite's popularity.
Common directives
gem -v 告訴你 RubyGems 的版本gem update --system 升級RubyGems的版本gem install gem_name 安裝某個套件gem list 列出安裝的套件gem update gem_name 更新最新版本gem update 更新所有你安裝的Gemsgem install -v x.x.x gemname 安裝特定版本gem uninstall gem_name 反安裝
When executed gem install gem_name
, it will automatically produce the RDoc and RI files for this kit after the installation. In the current network, it is often possible to find documents directly from Google or on the suite website, so it is not really necessary to produce files in the local terminal, and the time to install the installation time to occupy the hard disk space. There are two ways to omit this step:
Each time you install, add the following parameters:
$ gem install gem_name --no-ri --no-rdoc
Or add a ~/.gemrc
file as follows, the preset does not produce files:
gem: --no-ri --no-rdoc
Users of Linux need to add sudo, for example sudo gem install gemname
.
Install Ruby on Rails
$ gem install rails --no-ri --no-rdoc
In order to install the time of the installation of the file, this is added --no-ri
with the --no-rdoc
parameters. After the installation is complete, enter the rails -v
rails 4.2.0 you should see.
Under Ubuntu, you need to use the root installation Kit:sudo gem install rails
Users Windows Friends Unfortunately currently need a hand-nail action to use the Rubygem. First please download the Rubygems-update-2.2.3.gem and put it C:\
under the following:
$ gem install --local C:\rubygems-update-2.2.3.gem$ update_rubygems --no-ri --no-rdoc$ gem uninstall rubygems-update
Then you can gem install rails --no-ri --no-rdoc
install rails once.
Install Rails to develop the environment