RVM doesn't recognize installed gem, so bundle install fails - ruby-on-rails-3

Bundle install command fails because gem install pg fails:
Make sure that `gem install pg -v '0.17.1'` succeeds
I can though, install pg with certain options:
gem install pg -- --with-pg-include=/usr/pgsql-9.3/include --with-pg-dir=/usr/pgsql-9.3
Still.. running bundle install fails, saying:
Make sure that `gem install pg -v '0.17.1'` succeeds
Well ye I know it fails, that why I installed it before, with options given,
How do I make the bundle see it the gem is already installed.? (or maybe make the bundle command to run gem install pg -- --with-pg-include instead of gem install pg -v '0.17.1' so it will succeed)
I also use rvm, and i'm rather clueless about it, so maybe even though I the pg gem is installed:
gem list pg
*** LOCAL GEMS ***
pg (0.17.1)
The application doesn't recognized the installed pg gem? if so How do I make the application's rvm see that the required gem is already installed?
Thank you

Finally found answer: How can I pass a parameter for gem installation when I run bundle install?
So in my case:
bundle config build.pg --with-pg-include=/usr/pgsql-9.3/include --with-pg-dir=/usr/pgsql-9.3
bundle install
And that took a day, well could have been worse

So you know in the future, this wasn't an RVM issue. This was a bundler and gem command parameter passing issue. RVM wasn't involved at that stage.

Related

An error occurred while installing pg (0.12.2), and Bundler cannot continue

I'm following the Michael Hartl Ruby on Rails Tutorial & there is a part where he is he he instructs you to update your Gemfile to include:
group :production do
gem 'pg', '0.12.2'
end
And then enter the below commands in your terminal:
bundle update
bundle install --without production
When you run the bundle update command it throws back the below errors.
sample_app:$ bundle update
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.0.3)
Using i18n (0.6.4)
etc
[omitted lines for brevity]
etc
Using railties (3.2.12)
Using coffee-rails (3.2.2)
Installing diff-lcs (1.1.3)
Using jquery-rails (2.0.2)
Installing pg (0.12.2)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/ross/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
etc
[omitted lines for brevity]
etc
Gem files will remain installed in /home/ross/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2 for inspection.
Results logged to /home/ross/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2/ext/gem_make.out
An error occurred while installing pg (0.12.2), and Bundler cannot
continue.
Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.
sample_app:$
I was able to overcome this error easily be removing the 'pg', '0.12.2' gem from the Gemfile & replacing it after running the bundle update command. This seems to work fine as the 'pg', '0.12.2' gem is aslo omitted in the without production flag in the latter bundle install --without production.
The 'pg', '0.12.2' gem is only needed for deploying to heroku with the correct database & everything works fine even when I deployed it to heroku but I'm just wondering if this is an error in the Tutorial or am I missing something bigger here?
It's also annoying to have to remove this Gem everytime I run bundle update, is bundle update really that necessary?
Thanks in Advance
I'm following the same tutorial and I think it's redundant to run update without modifying existing dependency, but in this case it's even causing problems because update command has not --without argument.
I stumbled upon Rails 3 cheatsheet which mentions bundler workflow this way:
After adding or removing dependencies from Gemfile
$ bundle
Commit Gemfile and Gemfile.lock
After modifying existing dependency versions
$ bundle update
Commit Gemfile and Gemfile.lock
I read man pages for bundle update and tried RECOMMENDED WORKFLOW which consists of running bundle update after bundle install.
In my case (some output omitted):
$ bundle install --without production
Resolving dependencies...
Using rake (10.0.3)
...
Installing rspec-core (2.11.1)
Your bundle is complete!
Gems in the group production were not installed. <-- check
$ bundle update
Resolving dependencies...
Using rake (10.0.3)
...
Using uglifier (1.2.3)
Your bundle is updated!
Gems in the group production were not installed. <-- check
I tried it with new RVM gem set and everything was installed correctly.
After that Gemfile.lock contains pg (0.12.2) and deploying to Heroku works.
RECOMMENDED WORKFLOW
In general, when working with an application managed with bundler, you
should use the following workflow:
After you create your Gemfile for the first time, run
$ bundle install
Check the resulting Gemfile.lock into version control
$ git add Gemfile.lock
When checking out this repository on another development machine, run
$ bundle install
When checking out this repository on a deployment machine, run
$ bundle install --deployment
After changing the Gemfile to reflect a new or update dependency,
run
$ bundle install
Make sure to check the updated Gemfile.lock into version control
$ git add Gemfile.lock
If bundle install reports a conflict, manually update the specific
gems that you changed in the Gemfile
$ bundle update rails thin
If you want to update all the gems to the latest possible versions
that still match the gems listed in the Gemfile, run
$ bundle update
Installation of postgres fails with this error : "Can't find the 'libpq-fe.h header"
Looks like a lot of people faced this problem, good news is : stackoverflow has the answer ;)
Can't find the 'libpq-fe.h header when trying to install pg gem
(or at least it should help you to look in the right direction)

Omniauth + Devise Error: Could not find hashie-1.2.0

I add this to Gemfile:
gem 'omniauth-facebook'
Then I run bundle update. No problem so far. But when I run rails server I get this error:
Could not find hashie-1.2.0 in any of the sources
Run `bundle install` to install missing gems.
I thought that bundler was supposed to resolve and satisfy all dependencies, but I tried this anyway:
gem install hashie-1.2.0
Which gave this:
ERROR: Could not find a valid gem 'hashie-1.2.0' (>= 0) in any repository
ERROR: Possible alternatives: hashie-model
I'm new to Rails and I feel I'm at a dead end. Suggestions?
UPDATE: I also have run bundle install (to be exact bundle install --without production) several times. I get the same error when running rails server after that.
UPDATE: I aslo tried adding gem 'hashee' in the Gemfile before omniauth-facebook. No luck.
So I think you are just using bunder incorrectly.
bundle update doesn't resolve new dependencies, it simply looks at the gem manifest, which is stored in Gemfile.lock and updates those gems to the most recent gem allow by the constraints placed on them in the Gemfile.
Since you are trying to install a new gem, what you what to run is bundle install which will make a comparison between your Gemfile and your Gemfile.lock and install any gems that are not listed in your Gemfile.lock.
I think bundle install should do the trick for you.
As a side note, bundler tries to make this as easy as possible for you by aliasing bundle to bundle install. So, unless you are explicitly looking to update your gems, you can just type bundle and get the behavior that you are expecting.
I got it working. I think it was some problem with bundler. I did some different things, and I have to admit that I'm not 100% sure what fixed it. I think what did it was this:
gem uninstall bundler
gem install bundler
bundle install mail
However, it did not work until my second reinstall I think. Upon the install command, it installed everything, not just mail and its dependencies. The only other thing I did was to delete /usr/bin/bundler after the first reinstall. It did not reappear.

How to uninstall a gem from Rubymine

I'm a n00b in Rails and Rubymine IDE. The Rubymine Help says to
To uninstall gems, use command line procedure. So doing, the
recommended command format depends on the Ruby gems version you use.
gem uninstall <gem_name>
Could not how to figure out where to run the command and the Help does show this either. Let me know if there are any add'l steps that need to be done, such as unbundling the gem.
Thanks in advance.
Just run in the terminal/console a command:
gem install <gem_name>
In case if you using several RVM sets, then go to File/Setting/Ruby SDK and Gems and check which gem set used by RubyMine. Then check the gemset in terminal by command:
rvm gemset list
You will see the current gem set, you can change it if you need by command:
rvm gemset use <gemset_name>
And then do the uninstalling.

Bundle install keeps installing to ./runner

Not sure what's going on here, but in my Rails 3 application, I type bundle install and at the end if says Your bundle is complete! It was installed into ./runner.
Weird because I have no idea where runner is coming from!
If I recall correctly, if you run something like bundle install ./runner it will remember the path ./runner. bundle install --system should fix it. i think.
See the manpage:
--path=<path>
The location to install the gems in the bundle to.
This defaults to the gem home, which is the location
that gem install installs gems to. This means that, by
default, gems installed without a --path setting will
show up in gem list. This setting is a remembered option.
--system
Installs the gems in the bundle to the system location.
This overrides any previous remembered use of --path.

Ubuntu 11.04 Ruby on Rails install write permissions error

I am trying to install rails and have installed rvm and am trying to install rails but it is saying I do not have write permissions.
$ gem install rails --version 3.0.7
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.8 directory.
When I try sudo it give me this error, I know that you can use --no-ri --no-r-doc but even when I did this rails was not installed properly. Does anyone have any ideas?
$ sudo gem install rails --version 3.0.7
Successfully installed rails-3.0.7
1 gem installed
Installing ri documentation for rails-3.0.7...
file 'lib' not found
Installing RDoc documentation for rails-3.0.7...
file 'lib' not found
from my experience with rvm, gems should't stay in /var/lib/
if you didn't specifically asked for this, there might be a problem with your rvm installation
if so, i would definetly recommend a clean rvm install by following ryan bigg's guide of installing rvm. i followed it every time and never ever had the slightest problem after.
hope this helps!