8

I am attempting to use bundle install. I am not a Ruby user - this is my first real foray into even running rake. I'm simply trying to user some packages from ThrowtheSwitch.org that use Rake and so on.

I initially installed ruby several days ago using:

sudo apt-get install ruby-full

This allowed me to use rake with Unity testing framework. Now I'd like to use CMock. the instructions for using CMock say to cd into the directory then

$ bundle install
$ bundle exec rake

So I install bundler using:

$ sudo apt-get install bundler

But then running the bundle install continuously asks me for my password. So I try:

$ gem install bundler

Which fails for write permissions on /var/lib/gems/1.9.1. So I try:

$ sudo gem install bundler

which installs OK so I try the bundle install again. But still get continuously asked for my password. So I try:

$ sudo bundle install

And get a warning that I should not run bundler as root:

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.

How can I install this properly so that I can run it as expected?

Note: I have seen that there are several other questions on this topic, none of which I understood the answers to so let me underline that I am not a ruby (or even web stack) dev - I need this in layman's terms as much as possible.

Note also: I did see several mentions of RVM and rbenv. I'm not sure if they were incidental to those questions in particular or if one or both is required. I do not currently have either. Am about to research exactly what they are now.

Note the third: My platform is WSL (so Ubuntu, kind of).

Toby
  • 9,696
  • 16
  • 68
  • 132
  • Also, is there a difference between `apt-get install bundler` and `gem install bundler`? – Toby Nov 02 '16 at 17:06

3 Answers3

3

I've been working with Ruby only a few weeks now. I'll say, I know where you are. I am not about to help much but will say, to your last question in the comments, that my understanding is that the two commands are different.

My understanding of a short answer.. One can have diff versions of Ruby they need to work with (legacy projects, etc) and not every version of Ruby can run every version of a given gem. For this reason, one can use rbenv or rvm to help manage the art of setting up a project with a particular version of ruby and then installing the needed gems.

I've been working with rvm on my mac and rbenv in linux and find them both similar enough for the simple stuff I've been doing. Installing rbenv on linux proved slightly easier. Once set up properly, sudo is no longer needed to install gems - which is preferred. I would recommend trying one of these and installing per their website instructions. Things should go smoother once set up.

Rachel
  • 56
  • 3
  • Thanks for the info. In conjunction with veldtmana's answer this helped me understand things (a little) more. I went with rbenv in WSL and its worked a lot more easily than my aborted attempt at using RVM! – Toby Nov 03 '16 at 13:27
2

Try running:

gem install bundler
bundle install

I will try to explain how the ruby ecosystem works:

Bundler is a gem - a module - that is installed on top of ruby. Gems are installed using

 gem install <gem name>

I would recommend you look at installing a ruby version manager before doing anything else. the two main candidates are RVM and rbenv.

I find RVM is the simpler option for the beginner, but it eats up more space on your hard drive.

after you have installed ruby you can test that it is installed correctly by calling ruby -v from the command line.

After that you can install bundler by calling gem install bundler

Once the gem is installed you should be able to run bundler, however if you are using rbenv you might need to run rehash first

I hope that explanation makes sense - please shout if you have questions.

veldtmana
  • 176
  • 6
  • Thanks. I tried RVM first but it was hopelessly complicated FWIW and I couldn't get it to work right (I think my previously root installed vbundler was still being used) so I uninstalled everything (past ruby install & bundler included) then went with rbenv. Aside from making sure I used `.bashrc` where the installation guide mentions `.bash_profile`, this has worked like a dream. (I also added `rbenv local 2.3.1` to the .bashrc so that ruby would already be selected when I open bash). – Toby Nov 03 '16 at 13:25
2

If you - for some reason - stuck with a system installation of ruby, this does the job:

export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$GEM_HOME/bin:$PATH"

found it elsewhere: https://guilhermesimoes.github.io/blog/using-bundler-with-system-ruby

hartmut
  • 41
  • 1
  • 3