Ubuntu 18.04.4 LTS 64 bit
***** installed via system repository *****
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
rails 2.5.0
bundle 1.16.1
No ruby enviroment contoller (like RVM) installed
Number of issues arose from wanting to “add” a gem to my rails app via bundle, below i try to explain those issues/problems as I’ve found similar things on the web.
- wanting to install via bundle a new gem from gems repository and no where else.
- Stop the annoying errors which boiled down to …
- Native extension failure and permissions.
How i dealt with Native Extension error!
Original errors where like those below (please note this gem depend on bcrypt 3.1.13 as being current at this time)
bundle install devise 4.7
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Installing device 4.7.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
bundle install --path vendor/bundle
Right here is the 1st hint - namely native extension error.
to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to Rubygems using sudo.
Password:
And here is the hint to have the gem installed somewhere else (be it in the project directory - but then if you want it again it isn’t global and you end up with multile copies).
To my SHAME I entered my sudo password to try and solve this, It then popped up an error stating that bcrypt wasn’t installed and to read all about it in the log file and that the gem would stay there.
So now i got hammered twice
- 1st time for devise
- 2nd time for bcrypt.
NOTE:
If (you have/are) having had this type of issue I'm sure you'll be more than familiar
with the error message(s) being produced.
So lets deal with the “permissions” problem.
The 1st (below) gave me an inkling of how to possibly solve my problem but I’m not too keen on mucking with my user scripts in home.
Due to having a link constraint on my 1st posting here please remove spaces in the url below
https: //github .com/chef/chef-dk/issues/148
Link below showed me what to add into my .profile script in /home.
https://guilhermesimoes.github.io/blog/using-bundler-with-system-ruby
edit .profile script to include these lines below is the bottom line of teh above url.
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$GEM_HOME/bin:$PATH"
The above link talks about editing the .profile script in /home (even though I’m not too happy to edit it i thought it’d be okay - having the gem installed into the global repository in another way).
I did this and it went away (but i used sudo install bcrypt - this was the ONE gem not yet installed).
It got installed into /home/.bundle/cache… and file permissons got affected because as soon as i ran bundler install errors where throwen up at me.
I corrected the errors by using command line
chown -HR username:groupname .bundle/
actually i used my username (dave) and my groupname (dave) -HR are for recursively go through directories and files and -H is for symbolic links (this maybe dangerous in other circumstances be awear of this).
re-ran bundle and all was good.
even though i still have the native extension error.
Overnight i thought about it and in the morning my mind made up I googled for help on native extension postings to see if i could fix this completely) and so we move on…
Native Extension issue
I wanted not to have the native extension error at all and believed that the Gem::Ext::BuildError would be sorted as well.
I had both devise & bcrypt installed in two locations
- devise in with other gems that where initially installed with ruby and rails
- bcrypt in my /home/.bundle directory
This i decided i didn’t like, I wanted all gems i wanted to install subsequently to be put in with the other (system gems others may argue otherwise, i decided it my way).
so i uninstalled bcrypt from .bundle using sudo gem uninstall.
I then had to redo the chown command.
Now how did i sort out the Native Extension issue?
I googled using ruby error failed to build gem native extension
I the replies they spoke of developer files from the linux (Kubuntu) system repository.
I already had build-essentials installed in my system and then started looked for other ruby dev files, Finding, ruby-dev description is shown below.
Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in perl). It is simple, straight-forward, and extensible.
This package contains the header files and the mkmf library, necessary to make extension library for Ruby. It is also required to build many gems.
This package is a dependency package, which depends on Debian's default Ruby version (currently v2.5).
Canonical provides critical updates for ruby-dev until .
As I’d read else where about the mkmf library i took a gamble, installed it then reinstalled via sudo gem install devise and as showen below the result was a clean install - NO EXTENSION ERRORS!
sudo gem install devise
Successfully installed devise-4.7.1
Parsing documentation for devise-4.7.1
Done installing documentation for devise after 1 seconds
1 gem installed
dave@main-dave:/downloads/ruby projects/week1$
after installing i sudo gem installed
sudo gem install bcrypt
Building native extensions. This could take a while...
Successfully installed bcrypt-3.1.13
Parsing documentation for bcrypt-3.1.13
Done installing documentation for bcrypt after 0 seconds
1 gem installed
Please note
I hope that this will help someone sometime in the future.