Reputation: 4497
I'm quite newbie in ruby and ruby on rails and I'd like some clarification, if possible.
I'm currently having rails 4.2.6
installed on my development environment in which I have built a few projects. Now, for my new projects I'd like to use Rails 5, so I assume that if I type the gem install rails
command will get me the latest rails verion and probably set it as default, so every time I want to create a new project by rails new my_new_project_name
this project will have the latest version (currently v5).
My question is will my gem list contain both rails versions then or is it going to cause any conflicts and issues to my old porjects? so, if I want to work back on any of my projects which has the "old" version, won't affect of any changes, right? As far as I understand its the bundler
who picks the version of each gem, right?
If thats the case, I assume same thing applies and for every other gem that I use for each project, right?
Upvotes: 1
Views: 1778
Reputation: 19
I solved this kind of dependence issues by moving all my developments to docker. So now I have a unique environment for each project trough use of Dockerfile.
I also employ Makefile and compose.yml to automatize by ci. Hope that help.
Upvotes: 0
Reputation: 352
Best thing to do when using different versions of a same gem is to use either rbenv or RVM to create different gemsets for each project. This way You can be sure that your project won't load by mistake another version .
I personally use RVM so i am going to let You know how to use it.
1) install RVM from here https://rvm.io
2 ) make sure You are loading RVM in your .bashrc or .bash_profile files from your home directory ( /home/your_username) . You can use this code:
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
3) take a look at this page https://rvm.io/workflow/projects and choose how You want to set RVM for your project . i personally use .rvmrc because i am old school...but those are not recommended anymore because they need trusting and are slower. As a alternative You can use .ruby-version and .ruby-gemset files. But You can use .versions.conf also If You want. Let's say for now we choose to use .ruby-version and .ruby-gemset files.
4) cd into your project and run this command `rvm --ruby-version use 2.3.3@project1 --create' . This will generate those two files în your project . And everytime You will cd into this project RVM will pick-up the gemset automatically.
5) Do the step 4) for the second project also but replace 'project1' with 'project2' .
6) Now You can edit the Gemfiles of these two project and put the version of rails that You desire.
7) to install each project You need to cd into that directory and run command 'gem install bundler' ( only first time) and then You can safely do 'bundle install'
8) repeat 7) for second project.
9) You are all Done. Now You have different version of same gem in two different gemsets .
To also answer the other questions:
1) having în the same gemset multiple versions of same gem can lead to conflicts especially when doing 'rails new project ' from terminal since this doesn't require a specific version . I suggest to create different gemset before installing a new version of a existing gem on your machine. For example for this particular case we can do this
rvm use 2.3.3@rails5 --create
gem install bundler
gem install rails -v 5.O.0.1
And now we can safely do 'rails new project' . This way the new version of rails is inside a new gemset .
I Hope this will help You :)
Upvotes: 2
Reputation: 1583
You will have all different versions. BUT you will need to add the version number for all gems to your gemfile
and in the gemfile
you state:
gem 'remotipart', '1.2.1'
Upvotes: 2