rails--installation and startup

Install Rails

(The commands are all on the Linux side.)

1. Install ruby, enter the command

●  $ gem install bundler

● $ gem install rails -v 4.2.11.3

2 A series of commands will appear during installation, finally enter $ rails -v, and see the version number displayed, it is installed

gem install bundler

gem install rails -v 4.2.11.3

rails -v

Create a Rails project

Use the command:

$ rails new <project name>, for example:

● $ cd /workspace

● $ rails new library

Created a project named: library.

At the same time, a series of files is created, which automatically executes the 'bundle install' command.

Rails uses bundler to manage various dependencies

Rails uses bundler to manage various dependencies

There are also many third-party package gems (little gems) in ruby. Every Rails project depends on many gems.

In java, use maven, ivy to manage. In Rails, use bundler to manage.

bundler manages .

File: Gemfile. Defines all gem versions.

Command:  $ bundle install , will automatically install all gems.

Use Gemfile to install various dependencies.

Edit your Gemfile (under the root directory) to make its content look as follows: (Now use rails4.2.11.3 version may be because the version is relatively low, the content in Gemfile can also be adjusted according to the content in Gemfile.lock ) can also be empty, and then copy and paste

  • source 'https://gems.ruby-china.com'
  • # source 'https://rubygems.org'
  • gem 'rails', '4.2.11.3'
  • gem 'sqlite3', '1.3.11'
  • gem 'sass-rails', '4.0.5’
  • gem 'uglifier', '3.0.2'
  • gem 'therubyracer', '0.12.2', platforms: :ruby
  • gem 'jquery-rails', '3.1.4'
  • gem 'turbolinks', '5.0.1'
  • # gem 'mini_racer'
  • gem 'execjs', '2.7.0'

Install various dependencies, gems.

If ubuntu cannot use the sqlite3 dependency, install the sqlite3 dependency first:

$ sudo apt-get install libsqlite3-dev

Then pass the command:

$ bundle install is enough.

run rails

Use the command:

$ bundle exec rails server

bundle exec: is the prefix of the rails command (exec will tell rails that the gems used in the future are all the versions specified in the Gemfile)

Guess you like

Origin blog.csdn.net/Toml_/article/details/131568015