Using postgres as default in rails - ruby-on-rails

I'm a newbie in ruby and rails development. I know that rails uses sqlite3 as default, so I want to try using postgres as defalut. I've downloaded postgres, jruby, ruby 2.5.1, rails 5.2.1. I've intalled ruby devkit with ruby dk.rb init/install. I'm stumbled into the wall when I try to install pg gem, I get the following output:
Building native extensions. This could take a while...
C:/jruby-9.1.17.0/lib/ruby/stdlib/rubygems/ext/ext_conf_builder.rb:58: warning: Tempfile#unlink or delete called on open file; ignoring
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: C:/jruby-9.1.17.0/lib/ruby/gems/shared/gems/pg-1.1.3/ext
C:/jruby-9.1.17.0/bin/jruby.exe -r ./siteconf20180918-6200-16mdyzt.rb extconf.rb
checking for pg_config... yes
Using config values from C:\postgres\bin/pg_config.exe
RuntimeError: The compiler failed to generate an executable file.
You have to install development tools first.
try_do at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:456
try_link0 at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:541
try_link at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:556
<main> at extconf.rb:40
*** 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
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/jruby-9.1.17.0/bin/jruby
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/jruby-9.1.17.0/lib/ruby/gems/shared/extensions/universal-java-1.8/2.3.0/pg-1.1.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/jruby-9.1.17.0/lib/ruby/gems/shared/gems/pg-1.1.3 for inspection.
Results logged to C:/jruby-9.1.17.0/lib/ruby/gems/shared/extensions/universal-java-1.8/2.3.0/pg-1.1.3/gem_make.out
mkmf.log contains:
find_executable: checking for pg_config... -------------------- yes
--------------------
" -o conftest.exe -I/include/universal-java1.8 -IC:/jruby-9.1.17.0/lib/ruby/include/ruby/backward -IC:/jruby-9.1.17.0/lib/ruby/include -I. -IC:/postgres/include -fno-omit-frame-pointer -fno-strict-aliasing -fexceptions conftest.c -L. -LC:/jruby-9.1.17.0/lib -LC:/postgres/lib -LC:/jruby-9.1.17.0/lib/native/x86_64-Windows -m64 -march=native -mtune=native "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <ruby.h>
4: int main(int argc, char **argv)
5: {
6: return 0;
7: }
/* end */

Have you installed postgres package in your system You can install in linux using command
sudo apt-get install postgresql postgresql-contrib
if you are using debian system
The error clearly states that that you need to install development tools so you may have likely missed installing some dependencies
You can install through command line utitlities using the commands
#powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://s3.amazonaws.com/pgcentral/install.ps1'))"
cd bigsql
pgc install pg10
pgc start pg10
Please follow this link to configure postgress in windows
To install postgres client, please refer to this stackoverflow link and also try to install pg gem by specifying the path of pgconfig file you can refer to this
link for example

Related

gem install pg for ruby on rails, error message: lack of necessary libraries and/or headers

I am new to ruby and encounter when I was trying to gem install pg and get this problem
Building native extensions with: '--with-pg-lib=/usr/lib'
This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
checking for pg_config... yes
Using config values from /home/linuxbrew/.linuxbrew/bin/pg_config
checking for libpq-fe.h... *** 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
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/chensiyuan/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib=${pg-dir}/lib
I have checked the log file and it shows like this
gcc: error: unrecognized command line option '-Wmisleading-indentation'
gcc: error: unrecognized command line option '-Wimplicit-fallthrough=0'
gcc: error: unrecognized command line option '-Wduplicated-cond'
gcc: error: unrecognized command line option '-Wrestrict'
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
I have already installed the postgresql by
sudo apt install linuxbrew-wrapper
sudo apt-get install build-essential
sudo apt-get install libpq-dev
brew install postgresql
That's what I have done for this problem after I searched other notes. Can someone please help me out here? I have checked all the possible duplicate and the above commmands are from those answers. However, my ubuntu still complains about the same issues.
If your brew install postgresql was installed successfully installed, then try bundle install in the ruby app again.

Azure: Rails and PostgreSQL on the same VM?

I'm trying to combine a Rails app and PostgreSQL on the same Azure virtual machine.
I installed PostgreSQL 9.5 following this guide and it seems to give no problems by itself. Now the problem is, I cannot install the pg gem. Specifically, running the command gem install pg -v '0.19.0', it gives me the following error:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/pg-0.19.0/ext
/usr/bin/ruby2.3 -r ./siteconf20170122-18144-1ee3id1.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
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
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/$(RUBY_BASE_NAME)2.3
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/pg-0.19.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.3.0/gems/pg-0.19.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/pg-0.19.0/gem_make.out
Any help is really appreciated. Cheers
What is the response of which pg_config
If it is something like:
/usr/bin/which: no pg_config in...
Try installing again with below command:
sudo apt-get install postgresql-devel
As simple as it was, I just needed to install postgresql-server-dev-9.5 on my Azure Ubuntu VM. I just overlooked the error log :D

I got to error installing pg gem

I'm on Ubuntu 10.04, how to fix this error?
When I use bundle install command, this install the necessary gems for run the app with rails s.
But "bundle install" command fails too.
I don´t understand the console prompt, can somebody help me?
antonio#antonio-desktop:~/Descargas/ecozap$ gem install pg -v 0.15.1
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p484/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
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/rvm/rubies/ruby-1.9.3-p484/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
extconf failed, exit code 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p484/gems/pg-0.15.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p484/extensions/x86-linux/1.9.1/pg-0.15.1/gem_make.out
When I used the sudo apt-get install libpq-dev, I´m getting the following error:
antonio # antonio-desktop: ~ / Downloads / ECOZAP $ sudo apt-get install libpq-dev
[sudo] password for antonio:
E: Failed to lock / var / lib / dpkg / lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/ var / lib / dpkg /), maybe there is another process using it?
All you have to do is close any other package manager that is locking apt and install libpq-dev again.

Can't run the command -- rake:install

When I run the command rake:install, I get this error message:
WARNING: 'require 'rake/rdoctask'' is deprecated. Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
at /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
Successfully built RubyGem
Name: mysql2psql
Version: 0.1.0
File: mysql2psql-0.1.0.gem
Executing "ruby -S gem install ./pkg/mysql2psql-0.1.0.gem":
ruby -S gem install ./pkg/mysql2psql-0.1.0.gem
Building native extensions. This could take a while...
ERROR: Error installing ./pkg/mysql2psql-0.1.0.gem:
ERROR: Failed to build gem native extension.
/Users/adam/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for pg_config... no
=========== WARNING ===========
You are building this extension on OS X without setting the
ARCHFLAGS environment variable, and pg_config wasn't found in
your PATH. If you are seeing this message, that means that the
build will probably fail.
If it does, you can correct this by either including the path
to 'pg_config' in your PATH or setting the environment variable
ARCHFLAGS to '-arch <arch>' before building.
For example:
(in bash) $ export PATH=/opt/local/lib/postgresql84/bin:$PATH
$ export ARCHFLAGS='-arch x86_64'
(in tcsh) % set path = ( /opt/local/lib/postgresql84/bin $PATH )
% setenv ARCHFLAGS '-arch x86_64'
Then try building again.
===================================
MacOS X build: fixing architecture flags:
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
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/radek/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
--with-pg
--without-pg
--with-pg-config
--without-pg-config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--enable-static-build
--disable-static-build
Gem files will remain installed in /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.9.0 for inspection.
Results logged to /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.9.0/ext/gem_make.out
rake aborted!
Command failed with status (1): [ruby -S gem install ./pkg/mysql2psql-0.1.0...]
Tasks: TOP => install
(See full trace by running task with --trace)
Apparently is the problem in the pg gem, but when I check the list of installed gems in my application, so there is * pg (0.13.2)
So what I am missing yet?
Solution for the issue above:
1. export PATH=/Library/PostgreSQL/9.1/bin:$PATH
2. export ARCHFLAGS='-arch x86_64'
3. rake install

Rails wants pg 0.10.0 but I can only install pg 0.10.1

I'm on Mac OS X. If I run sudo env ARCHFLAGS="-arch i386" gem install pg, it works just fine. However, I get this error when I try to visit my Rails project in the browser:
Could not find pg-0.10.0 in any of the sources (Bundler::GemNotFound)
If I then uninstall 0.10.1 and try to install 0.10.0, I get this:
$ sudo env ARCHFLAGS="-arch i386" gem install pg --version 0.10.0
Password:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for pg_config... yes
Ruby cflags: "-arch i386 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common "
MacOS X build: fixing architecture flags:
using the value in ARCHFLAGS environment variable ("-arch i386").
finding flags common to both Ruby and PostgreSQL...
testing for architecture: "ppc"
testing for architecture: "i386"
common arch flags: -arch i386
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
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
--with-pg
--without-pg
--with-pg-config
--without-pg-config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.10.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.10.0/ext/gem_make.out
I don't care whether I find a way to make Rails accept pg 0.10.1 or if I find a way to install pg 0.10.0, but I need to do one or the other.
Is version 0.10.0 listed in your Gemfile.lock? If so, you should be able to update the version Rails is looking for by running bundle update pg, assuming your Gemfile doesn't also specify version 0.10.0.

Resources