Ruby: Difference between revisions

From 太極
Jump to navigation Jump to search
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Installation on Ubuntu =
= Installation =
== Windows, Mac ==
http://railsinstaller.org/en
 
== Ubuntu ==
* https://www.ruby-lang.org/en/documentation/installation/
* https://www.ruby-lang.org/en/documentation/installation/
* apt-get install ruby will install v1.8 or v1.9.
* apt-get install ruby will install v1.8 or v1.9. v1.8 is kind of old that nokogiri, for example, cannot be installed.
* I tried to install from the source (v2.2.1) on Ubuntu 14.04. The canonical method ./configure, make & sudo make install does not work at 'make' step. # See https://github.com/sstephenson/ruby-build/issues/690. Unfortunately the method of installing libffi-dev does not solve the error on Ubuntu 14.0.
* I tried to install from the source (v2.2.1) on Ubuntu 14.04. The canonical method ./configure, make & sudo make install does not work at 'make' step. # See https://github.com/sstephenson/ruby-build/issues/690. Unfortunately the method of installing libffi-dev does not solve the error on Ubuntu 14.0.
* The next method is [https://github.com/sstephenson/ruby-build#readme ruby-build]. Don't quite follow it.
* The next method is [https://github.com/sstephenson/ruby-build#readme ruby-build]. Don't quite follow it.  
 
http://stackoverflow.com/questions/26595620/how-to-install-ruby-2-1-4-on-ubuntu-14-04 mentioned a couple of methods.
* rbenv method. Not sure if it works since the shell hangs when I run 'rbenv install 2.2.0'.
* rbenv method. Not sure if it works since the shell hangs when I run 'rbenv install 2.2.0'.
* [http://rvm.io/ rvm (ruby version manager)] method.  
* [http://rvm.io/ <span style="color: red">rvm (Ruby Version Manager)</span>] method. This is the recommended method.
<pre>
<syntaxhighlight lang='bash'>
sudo apt-get update
sudo apt-get update
sudo apt-get install build-essential make curl
sudo apt-get install build-essential make curl
\curl -L https://get.rvm.io | bash -s stable
\curl -L https://get.rvm.io | bash -s stable
source ~/.bash_profile
source ~/.bash_profile
rvm install ruby-2.1.4
# sudo apt-get install ruby-rvm
time rvm install ruby-2.1.4
</syntaxhighlight>
The last step will take a while (27 minutes in my case) since no binary rubies for my OS/architecture were available and it has to compile Ruby from the source. At the end of installing, it will show
<pre>
Install of ruby-2.1.4 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
</pre>
</pre>
The last step will take a while since no binary rubies were available and it has to compile Ruby from source.


Then check ruby versions installed and in use
Then check ruby versions installed and in use
<pre>
<pre>
which rvm
# /home/brb/.rvm/bin/rvm
ruby -v
# ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-linux]
which gem
# /home/brb/.rvm/rubies/ruby-2.1.4/bin/gem
rvm list
rvm list
rvm use --default ruby-2.1.4
rvm use --default ruby-2.1.4
Line 24: Line 37:


= Documentation =
= Documentation =
https://www.ruby-lang.org/en/documentation/
* https://www.ruby-lang.org/en/documentation/
* [https://www.ruby-lang.org/en/documentation/quickstart/ Ruby in 20 minutes] from ruby-lang.org.
 
= Install Gems =
<syntaxhighlight lang='bash'>
# sudo apt-get install rubygems
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -L https://get.rvm.io | bash -s stable
source ~/.bash_profile
time rvm install ruby-2.1.4
rvm list
which ruby
gem install nokogiri
 
$ gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.6.2
Parsing documentation for nokogiri-1.6.6.2
Done installing documentation for nokogiri after 2 seconds
1 gem installed
 
$ gem list
*** LOCAL GEMS ***
bigdecimal (1.2.4)
bundler (1.7.4)
bundler-unload (1.0.2)
executable-hooks (1.3.2)
gem-wrappers (1.2.7)
io-console (0.4.2)
json (1.8.1)
mini_portile (0.6.2)
minitest (4.7.5)
nokogiri (1.6.6.2)
psych (2.0.5)
rake (10.1.0)
rdoc (4.1.0)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
test-unit (2.1.4.0)
 
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.2
  - RUBY VERSION: 2.1.4 (2014-10-27 patchlevel 265) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/mli/.rvm/gems/ruby-2.1.4
  - RUBY EXECUTABLE: /home/mli/.rvm/rubies/ruby-2.1.4/bin/ruby
  - EXECUTABLE DIRECTORY: /home/mli/.rvm/gems/ruby-2.1.4/bin
  - SPEC CACHE DIRECTORY: /home/mli/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
...
 
# Remove old ruby packages installed from apt-get
$ sudo dpkg -l | grep ruby
$ sudo apt-get purge ruby1.8*
 
</syntaxhighlight>
 
= Tutorials =
* lynda.com
* https://www.tutorialspoint.com/ruby-on-rails/index.htm
* https://www.javatpoint.com/ruby-on-rails-tutorial
* [https://youtu.be/pPy0GQJLZUM Ruby On Rails In 60 Minutes] (yt)

Latest revision as of 17:11, 24 November 2019

Installation

Windows, Mac

http://railsinstaller.org/en

Ubuntu

sudo apt-get update
sudo apt-get install build-essential make curl
\curl -L https://get.rvm.io | bash -s stable
source ~/.bash_profile
# sudo apt-get install ruby-rvm
time rvm install ruby-2.1.4

The last step will take a while (27 minutes in my case) since no binary rubies for my OS/architecture were available and it has to compile Ruby from the source. At the end of installing, it will show

Install of ruby-2.1.4 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

Then check ruby versions installed and in use

which rvm
# /home/brb/.rvm/bin/rvm
ruby -v
# ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-linux]
which gem
# /home/brb/.rvm/rubies/ruby-2.1.4/bin/gem
rvm list
rvm use --default ruby-2.1.4

Documentation

Install Gems

# sudo apt-get install rubygems
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -L https://get.rvm.io | bash -s stable
source ~/.bash_profile
time rvm install ruby-2.1.4
rvm list
which ruby
gem install nokogiri

$ gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.6.2
Parsing documentation for nokogiri-1.6.6.2
Done installing documentation for nokogiri after 2 seconds
1 gem installed

$ gem list
*** LOCAL GEMS ***
bigdecimal (1.2.4)
bundler (1.7.4)
bundler-unload (1.0.2)
executable-hooks (1.3.2)
gem-wrappers (1.2.7)
io-console (0.4.2)
json (1.8.1)
mini_portile (0.6.2)
minitest (4.7.5)
nokogiri (1.6.6.2)
psych (2.0.5)
rake (10.1.0)
rdoc (4.1.0)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
test-unit (2.1.4.0)

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.2
  - RUBY VERSION: 2.1.4 (2014-10-27 patchlevel 265) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/mli/.rvm/gems/ruby-2.1.4
  - RUBY EXECUTABLE: /home/mli/.rvm/rubies/ruby-2.1.4/bin/ruby
  - EXECUTABLE DIRECTORY: /home/mli/.rvm/gems/ruby-2.1.4/bin
  - SPEC CACHE DIRECTORY: /home/mli/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
...

# Remove old ruby packages installed from apt-get
$ sudo dpkg -l | grep ruby
$ sudo apt-get purge ruby1.8*

Tutorials