Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run bundle install as normal user

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).

like image 465
Toby Avatar asked Nov 02 '16 16:11

Toby


3 Answers

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.

like image 111
Rachel Avatar answered Oct 23 '22 21:10

Rachel


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.

  • check out how to install rvm at https://rvm.io/
  • alternatively look at rbenv at https://github.com/rbenv/rbenv

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.

like image 21
veldtmana Avatar answered Oct 23 '22 21:10

veldtmana


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

like image 25
hartmut Avatar answered Oct 23 '22 22:10

hartmut