Ruby on Rails - Ruby on Rails RVM - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
What is Ruby on Rails RVM?
- RVM stands for Ruby Version Manager.
- It is a command line tool which allows you to easily install, manage and work with different Ruby environments.
- With RVM, you can easily install different versions of Ruby and easily switch between them.
- Developing applications often times requires that you emulate different environments. Different versions of Ruby may be necessary for different projects.
- With conventional installations, this would impede your ability to be flexible.
RVM is maintained by the github community through pull requests sent to the project repository.
Basic Syntax:
- If you've already installed RVM, you should have the rvm command available to you. This is the way we call RVM
- The basic syntax of the command is:
rvm command_options command ruby_to_act_on
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
The RVM flags allows you to alter the behavior of RVM. To get the list of RVM commands, type the following:
rvm help
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
If you would like help on a specific command, you can reference it after "help" to get more detailed instruction:
rvm help command
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
How To Enable Tab Completion
We will enable RVM tab completion by putting the following line in our .bashrcfile:
[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
This will allow us to complete RVM commands by typing the TAB key twice after entering part of the command. For instance, we can type:
rvm inst
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
At this point, we can hit TAB twice, and it will complete to:
rvm install
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Using Gemsets:
- One way to distribute code in Ruby is to use a format called gems.
- Gems are installed to extend capabilities of the core Ruby distribution.
- And gems are often installed to get certain programs to function correctly.
- To provide certain Ruby environments, it is also possible to install gems that are only associated with a single Ruby installation.
- This functionality is called gemsets.
It means that you can have two different versions of same gem, or you can make gems unaware of other gems on a system. To see the available gemsets for the current Ruby, type the following command,
rvm gemset list
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
If you have more than one Ruby version installed, you can see all of the gemsets by typing,
rvm gemset list_all
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
By default, you should have two gemsets configured:
- default:
- This gemset is applied if no other gemset is specified.
- global:
- This gemset is inherited by every other gemset that is used. It does not need to be selected because it will be included automatically.
- You can create another gemset easily. We will create a gemset called "test_project" to demonstrate how this works:
rvm gemset create test_project
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
If you would rather copy a current gemset to a new gemset to run some tests, you can issue this command:
rvm gemset copy default test_project
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
We can change the gemset we wish to use:
rvm gemset use test_project
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
We can also change the Ruby version and gemset at one time. This is done giving the Ruby version, followed by the "@" character, and then specifying the gemset:
rvm use 2.0.0@test_project
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Now, we can install a Tic-Tac-Toe gem by issuing this command:
gem install tictactoe -v 0.0.4
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
We can now change to our default gemset and install an earlier version of the same gem:
- rvm gemset use default
- gem install tictactoe -v 0.0.3
We now have two separate versions of the Tic-Tac-Toe gem installed and we can test them independently by switching the gemset that we are using. If you're confused about which gemset you're currently working with, this command will print the current active gemset:
rvm gemset name
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
When you've finished using a gemset, perhaps because your testing is complete, you can get rid of it by issuing the following command:
rvm gemset delete test_project
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
ruby on rails tutorial tags - ruby , rail , ruby on rails , rail forum , ruby on rails tutorial , ruby tutorial , rails guides , rails tutorial , learn ruby
What is Gem Dependency?
- With RVM, no gems other than those required are installed.
- Due to this, working with multiple complex applications which has a long list of dependencies is much more efficient.
- RVM allows you to easily test gem upgrades by switching to a new clean set of gems to test with, while leaving your original set intact.
What is Gem Management?
- RVM provides you most flexible gem management system called Named Gem Sets.
- It lets you add a small text file to your application's repository, instead of checking in tons of gems.
- Only one downloaded version of each gem resides on disk rather than several copies because RVM's gemset management uses a common cache directory.
What is Update RVM?
RVM installation can be updated easily to a new version from within the utility. Run the following command:
rvm get stable
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
RVM will fetch and install newest version and then reload it. If your configurations are placed in config/db instead of user/db, it would be wiped out. To upgrade RVM to the latest version, type:
rvm get head