bundle install creating a 'parallel' folder in the rails app - ruby-on-rails

I'm currently working on a project which was changed from ruby version 2.0.0 to ruby verion 2.1.1,
i'm using rvm for maintaining my ruby versions. After installing ruby 2.1.1, I ran gem install bundler which installed version 1.6.2, doing so I had copied a specific gemset version to a newly created one for version 2.1.1 after which when running gem list on, it displayed all the gems, and when I tried to run the app it started throwing errors.
So when I ran bundle install again it created a separate folder parallel and installed the gems there. My question is why does this happen, is it a new feature of bundler 1.6.2'?
Initially I had my bundler version to 1.5.2.
Any input on this will be really helpful.
Thanks.

Found this post which explains clearly, the reason was my config file was corrupted.
we have to remove .bundle/config file and bundle install again.
rm -r .bundle/config
bundle install
click here for more information.
Thanks.

My guess is you have two different bundlers tied to a different RVM gemset, even if you tried to install the newest globally.
In the future you may consider using :
bundle install --path .bundle
to install your gems in a consistent manner, always in the same .bundle folder, no matter what RVM gemset you're using.

Related

Ruby: I cannot create gemfile.lock with default bundler version

I want to create my gemfile.lock file with bundler version 2.3.25
But when I try to bundle install it always is bundled with 2.4.5
So I uninstall bundler version 2.4.5 and it STILL bundles with that version, and then throws errors when I rails s because version 2.4.5 isn't there.
When I run gem list bundler right now I get: bundler (2.4.5, default: 2.3.25)
I've gone as far as to delete the file from
\\wsl$\Ubuntu\home\me\.rbenv\versions\2.7.0\lib\ruby\gems\2.7.0\gems\bundler-2.4.5
then, I delete the gemfile.lock file and bundle install and low and behold its bundled with 2.4.5..
I've tried gem uninstall bundler and no luck..
I've tried all of the following methods and no luck
Here
or
Here
How can I either force Ruby to use the default version of Bundler, or REALLY get rid of the version I don't want?
Bundler will add its version number to Gemfile.lock after you've run bundle install:
BUNDLED WITH
2.4.5
Therefore you can run bundle install with version 2.4.5 to generate Gemfile.lock and then edit it with a text editor to replace the version with the version you require. Then, when you run bundle install again bundler will notice that and will use the older version that you specify.
Gemfile.lock is a pretty straightforward and standard format and there are no material changes to it between those versions.
Otherwise, you can do like #engineersmnky said (and is explained in this other answer) and use:
bundle _2.3.25_ install

In a Ruby on Rails installation, what is causing webrick to be outdated and why `gem i webrick` can update it?

I have a new Mac computer and installed rails on it, and then I tried out the command
gem outdated
for some reason, it showed one of the gems outdated:
webrick (1.4.2 < 1.6.0)
I wonder why it is outdated on the first installed, and when I did
sudo gem install webrick
it actually installed 1.6.0 onto the system. Doesn't it require gem update instead of install to update something? How come install also updated it?
Not exactly, gem install GEM_NAME will install the last version available if you don't specify a version when installing, and you can have more than 1 version of the same gem on your machine.
you can run gem environment, and check where gems are installed, go to that folder and you will see both version gems folder there.
so when you create a rails project for example and add a specific version of a gem in the gemfile and another version on another project, you can have both without problems

RVM won't create gemset for a new project

RVM doesn't seem to be automagically creating a new gemset for a newly cloned git based rails project as it did for other projects when cding into the project folder. I get this message:
ruby-2.2.4 is not installed.
I am using ruby-2.3.1 and have set it as the default and that is the only ruby version I installed using rvm. Why am I getting that error message? I am on a MAC (Sierra OS) if that matters.
It started happening randomly as soon as I cloned a new project. I don't see ruby-2.2.4 being mentioned in the gemfile or the gemspec. Where is it picking it from?
If you paste the whole error message you get when trying to run bundle install it'll be easier to say for certain, but I'm assuming one of the gems in your gemfile requires Ruby version 2.2.4.
Just type in
rvm install 2.2.4
Then run bundle install again and all should be well, assuming no other errors.
You may need to switch which version of Ruby you're using based on which project you're in, just use
rvm use 2.4.0
rvm use 2.2.4
etc.

How do I delete gems for old ruby versions installed by bundler?

I want to free up disk space in my production environment taken up by gems installed for old ruby versions. I don't believe bundle clean will work in this instance, because I don't think it cleans out the old gems for other rubies.
These gems are installed via capistrano and are installed in a custom location, rather than system wide. In my /path/to/my-project/shared/bundle/ruby dir, I see 2 subdirs - 2.2.0 & 2.3.0. Since I am now using ruby 2.3, is it safe just to delete the 2.2.0 directory? Is there anything else I need to do?
Use "sudo gem cleanup" to remove all previously installed gems which respecting all the dependencies be it on old version of ruby. You can see all the gems that ll be removed with command "sudo gem cleanup -d"
here is how you can remove a specific version of the gem:
gem uninstall (gem name here) --version (version number here)
Go to Gemfile.lock and delete all its content. Then you go to Gemfile and delete gems you do not want anymore. After, You type bundle install and it will install just the ones you want.

gem path reverts back to previous path

just recently installed ruby 2.3.0 and rails 4.2
ran bundle install for the first time and my app successfully ran from my local server.
added a few gems, and once again ran bundle install... it appears that my previously installed gems were once again being installed.
tried running rails server once again and this came out.
-bash: /usr/local/bin/rails: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
just making a wild guess here, but i think the gem folder is reverting back to my old folder which is ruby 1.9.1
any form of help would be greatly appreciated.
You can read about different ways to set the app/project environment at rvm project workflows
if you are using rvm to manage the rubies, just add this line at the top of your gem file..
ruby '2.3.0' #or the target version of the app
or
#ruby=2.3.0
and cd back into the directory.. you'll get a warning but just ignore it. now every time you change back to you app directory it'll change the version to the one mentioned in your gem file. the default might be set to some other version..
you can also use
bash --login
rvm use '2.3.0' --default
to set the default version of ruby system wide.
if that doesn't work.. try to check if the correct ruby version is present by
rvm list
and then try using it by
bash --login
rvm use '2.3.0' #or the target version
and to every time switch to the latest version don't do anything above except when installing the version set it to default.. but you'll have to install all the gems again for every binary ruby you install..
P.S. Fixing ruby version for a project/app is a good and safe practice, so I'd recommend you to use the any approach to fix a ruby version for the app, mentioning it in Gemfile is clean, makes sense to me when you only need to set the ruby version.
Note. Do whatever is in #Shrikant1712's answer first if you haven't already or you might run into issues.
You have need to install gem bundler using gem install bundler command and then again try to use bundle install command.
(Here I am assuming you have used RVM for installing ruby.)
Still you get same type of error then that means your rvm is not properly set. Please check your $PATH from the following files
~/.profile
~/.bashrc
~/.bash_profile
~/.gemrc
You can use source ~/.rvm/scripts/rvm for setting the rvm.

Resources