Switching to postgresql for heroku deployment of rails application - ruby-on-rails

I have a rails application currently using sqlite3. Following this guide:
https://devcenter.heroku.com/articles/rails3 I'm trying to switch to postgresql. I changed my gemfile but when I run bundle install I get this error:
Errno::EACCES: Permission denied - /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.0/.gemtest
An error occured while installing pg (0.14.0), and Bundler cannot continue.
Make sure that gem install pg -v '0.14.0' succeeds before bundling.
so I try gem install pg -v '0.14.0' and get this error:
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Users/me/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.0/.gemtest
I found a few people with similar problems but I couldn't get it working. This is my first time trying to deploy a rails application so I don't have much intuition about what I'm doing.

Are you sure postgres itself is installed / correct?
the pg gem is the rails adapter, but you also need postgres itself on the machine.
e.g.
brew install postgresql
initdb /usr/local/var/postgres
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
rails new myapp -D postgresql
...
bundle install (install pg gem)

Related

Rails - Gem Error while installing pg (1.1.3), and Bundler cannot continue

I am still fairly new to Rails. I am trying to push to Heroku and I am getting errors.
The first error is when I run a Bundle Install I get this error message:
"An error occurred while installing pg (1.1.3), and Bundler cannot continue.
Make sure that gem install pg -v '1.1.3' succeeds before bundling."
I have tried to run this command
gem install pg -v '1.1.3'
But it fails and gives me this error message:
"ERROR: Error installing pg:
ERROR: Failed to build gem native extension."
Does anyone have a solution to this?
I had the exact same problem, and solved it by running sudo apt install postgresql-contrib libpq-dev. Then bundle worked just fine.
if you're using OSX, you could try running
brew install postgresql
and then installing the gem
TL;DR; If you installed the Postgres using the PostgresAPP instead of BREW then the problem might be that you don't have the postgres bin folder in the $APTH
The solution is to find the Posgres app installation folder an in it the /bin folder.
In my case if I run which postgres doesn't work which means I don't have it in my $PATH, so what I did is I navigated to: cd /Applications/Posgres.app then to Contents and then to Versions until I found the latest folder:
/Applications/Postgres.app/Contents/Versions/latest/bin
Now, with this I can install the PG GEM by providing the path to the bin folder of my Postgres app installation
Finally, in the terminal in the root of my Rails project I ran where I provide the postgres config file path to the GEM installer:
gem install pg -v '1.2.3' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
I encountered the same problem. I am using Ubuntu. I installed Postgres using this Ubuntu guide. After installing Postgres, I ran this code sudo apt install postgresql-contrib libpq-dev then bundle install.
The accepted answer is not correct. If you installed postgresql-contrib and libpq-dev as mentioned in Cesar Faria answer, and you still getting the same error, most probable you missed the list of packages which are considered essential for building Debian packages. All that packages included in build-essential package. So, all you need to do to get rid of the error is the command below.
sudo apt install libpq-dev build-essential
try instaling with pg-config like this:
gem install pg -v 1.1.3 -- --with-pg-config=/usr/pgsql-9.X/bin/pg_config.
In pg-config path mention the posgtres version installed in you're system.
Postgresql needs to be in local in order to install gem pg. Try this
brew install postgresql
and the re-install bundle
bundle install
or
If you are using yum. Try this
sudo yum install postgresql-devel
The following is only for your local environment:
Note: Update the command below to match your version postgresql/13.2/...
> brew install postgres
> sudo gem install pg -v '1.1.4' --source 'https://rubygems.org/' -- --with-pg-config=/usr/local/Cellar/postgresql/13.2/bin/pg_config
Also, make sure to start your server > pg_ctl -D /usr/local/var/postgres start

Rails bundle install has issues with postgres gem

I've been running into issues with pg in my Rails gem. When I try to..
$ bundle install
..my terminal returns..
An error occurred while installing pg (0.21.0), and Bundler cannot
continue.
Make sure that `gem install pg -v '0.21.0'` succeeds before bundling.
My gemfile includes this:
group :production, :default do
gem 'pg'
end
The exercise I am doing is to deploy my Rails app in Heroku, and it works. The idea is that I do not install postgres locally.
This is my Github repo, if it helps: https://github.com/cyqurayte/Rails1
The idea is that I do not install postgres locally.
I don't think it's possible to install this gem without having postgres already installed and updated
The reason this works on heroku is that the environment there already has postgres installed

Permission Error When Trying To Install Rails (OSX)

I am new to programming and am trying to get rails installed on my terminal. I have been following instructions from a friend, installing the xcode command line tools, homebrew, git, rbenv, ruby-build, ruby gems, ruby, and postgres. But whenever, I try $gem install rails, I get the following:
Russell-Silvers-MacBook-Pro:~ Russell_Silver$ gem install rails
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rails-4.2.0/README.md
This is especially frustrating because when I run $gem list, it says I have rails 3.2.18. Which is peculiar, because when I run $rails v$, it tells me I have Rails 4.2.0.
When I try to use rails rails my new_app
Errno::EACCES: Permission denied # rb_sysopen - /Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rails-4.2.0/README.md
An error occurred while installing rails (4.2.0), and Bundler cannot continue.
Make sure that `gem install rails -v '4.2.0'` succeeds before bundling.
run bundle exec spring binstub --all
/Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/shared_helpers.rb:83: warning: Insecure world writable dir /Users/Russell_Silver in PATH, mode 040707
bundler: command not found: spring
Install missing gem executables with `bundle install`
Russell-Silvers-MacBook-Pro:~ Russell_Silver$ bundle install
/Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/vendor/thor/shell/basic.rb:355: warning: Insecure world writable dir /Users/Russell_Silver in PATH, mode 040707
Could not locate Gemfile or .bundle/ directory
This is really frustrating, especially for someone new to programming such as myself, so I am seeking help from anybody who might know what is wrong.
Your rbenv installation was incorrectly installed as it had elevated privileges which caused your user account to not have write access to ~/.rbenv.
Issue the following command in order to take of ownership of the directory:
sudo chown -R Russell_Silver ~/.rbenv
Note that some users may have a different rbenv directory, e.g. /usr/local/var/rbenv. This would take the place of ~/.rbenv in the above command.

heroku db:pull cant connect to my DB in ubuntu

So I recently updated ubuntu to 11.04 and then downgraded back to 11.04 because I hated unity. Anyway, after I reinstalled 11.40 I had to clone all my old heroku apps and tried to run heroku db:pull to pull the DB and have it imported into my mysql db but I keep getting this error:
Failed to connect to database:
Sequel::AdapterNotFound -> LoadError: no such file to load -- mysql2
my gem file has gem 'mysql2', '< 0.3' and I gem installed taps already via RVM. I never had this issue when I ran db:pull before so I dont know what the problem is.
Im running ruby 1.9.2 with rails 3.0
run :
gem install mysql2 than heroku db:pull again ...
if you get this error with the previous "gem install mysql2" :
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
probably libmysqlclient-dev package should be installed :
sudo apt-get install mysql-server mysql-server-5.1 libmysqlclient-dev mysql-client-5.1 mysql-common
than
gem install mysql2
... or eventually run
locate mysql_config
then replace the resulting path, with in the following command path :
sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
You may have mysql2 in your Gemfile but have you done a bundle install - i.e. do you have the mysql2 gem installed ?
run :
gem install taps then heroku db:pull again
It may be work?

Ruby on Rail error installing SQLite, permissions problems

I've installed Ruby 1.8.7 and Rails 3.1.1 on my Mac OS X Leopard. However I wasn't able to install the SQLite gem. I've seen plenty solutions here, but none of the workout for me. Every time I tried to bundle my app I get this error when it comes to the SQLite gem:
Errno::EACCES: Permission denied -/Users/eduardoribeiro/sites/models/vendor/bundle/ruby/1.8/gems/sqlite3-1.3.4/API_CHANGES.rdoc
An error occured while installing sqlite3 (1.3.4), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.4'` succeeds before bundling.
I'm running
$ sudo bundle install
It seems that the compiler it's trying to install the sqlite dependecies inside of the folder of my app. I had the PATH correctly defined and even created a .bash_profile in the root of Mac OS X.
Any ideas?
Have you tried running gem install sqlite3 -v '1.3.4' at all before running bundle install ?
That could be your problem, if not try sudo gem install sqlite3 -v '1.3.4' then bundle install again.

Resources