Installation
I prefer to use version management to install various version of Ruby so that I can follow any tutorial that I found anywhere.
Via Homebrew
For macOS run this command:
|
|
Via Git
For Debian, Ubuntu, and their derivatives
- Clone rbenv into ‘~/.rbenv’ by running
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
- Add this lines into
~/.bashrc
|
|
- Set up rbenv in your shell
~/.rbenv/bin/rbenv init
and follow the printed instruction - Restart your shell so that PATH changes take effect. Or run
source ~/.bashrc
- Verify installation using rbenv-doctor:
~/.rbenv/bin/rbenv init
the result shall be
|
|
- Install rbenv-build (optional)
Using rbenv-installer
- rbenv-installer via script
|
|
- verify installation
|
|
Using rbenv
All guidence for using rbenv
can be found in this help command rbenv -h
|
|
Using Gem
Gem is package management in Ruby. Some guidance for Gem also can be found in gem -h
.
To install specific version of gem, you can follow this flow, the example of rails insstallation
Install Rails
Using Gem, you can install Rails, the most popular web framework in Ruby!
- Checking rails in local
gem list rails --local
- If you do not find the desired version on local, you can install using command like
gem install rails -v '5.2.3' -V --no-document
. - Not sure if the version is exist, check use
gem search '^rails$' --all
- You also can check other installed gems
gem list --local
- Generate new project with specific Rails version, for instance
rails _6.1.4.1_ new appname
- Go to appname directory and check Rails version
rails -v
- To run Rails server locally, use
rails s
Comparison to Golang
As Ruby is my second language, it is easier for me to learn Ruby by comparing this syntax with language that I am familiar with :)
Ruby | Golang |
---|---|
Gemfile.lock | go.sum |
Gemfile | go.mod |
bundle i |
go mod tidy |
rails new app_name |
go mod init project_name |
References: