Error installing gem pg version 0.12.2 on Ubuntu 12.04

im works on Ubuntu 12.04, and I'm trying to install pg gem v '0.12.2' on Ruby 1.9.3p194 / Rails 3.2.3. I installed libpq-dev and build-essential, but I still get the same error:

ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /var/lib/gems/1.9.1 directory. fernando@ubuntu :/media/fernando/OS/Rails/oops_booking$ sudo gem install pg -v '0.12.2' Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb checking for pg_config... yes Using config values from /usr/bin/pg_config checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for PQconnectdb() in -lpq... yes checking for PQconnectionUsedPassword()... yes checking for PQisthreadsafe()... yes checking for PQprepare()... yes checking for PQexecParams()... yes checking for PQescapeString()... yes checking for PQescapeStringConn()... yes checking for PQgetCancel()... yes checking for lo_create()... yes checking for pg_encoding_to_char()... yes checking for PQsetClientEncoding()... yes checking for rb_encdb_alias()... yes checking for rb_enc_alias()... no checking for struct pgNotify.extra in libpq-fe.h... yes0 checking for unistd.h... yes checking for ruby/st.h... yes creating extconf.h creating Makefile make compiling compat.c compiling pg.c pg.c: In function 'pgconn_wait_for_notify': pg.c:2117:3: warning: 'rb_thread_select' is deprecated (declared at /usr/include/ruby-1.9.1/ruby/intern.h:379) [-Wdeprecated-declarations] pg.c: In function 'pgconn_block': pg.c:2592:3: error: format not a string literal and no format arguments [-Werror=format-security] pg.c:2598:3: warning: 'rb_thread_select' is deprecated (declared at /usr/include/ruby-1.9.1/ruby/intern.h:379) [-Wdeprecated-declarations] pg.c:2607:4: error: format not a string literal and no format arguments [-Werror=format-security] pg.c: In function 'pgconn_locreate': pg.c:2866:11: warning: variable 'lo_oid' set but not used [-Wunused-but-set-variable] pg.c: In function 'find_or_create_johab': pg.c:3947:3: warning: implicit declaration of function 'rb_encdb_alias' [-Wimplicit-function-declaration] cc1: some warnings being treated as errors make: *** [pg.o] Error 1 

I have successfully installed the latest version of pg gem, but I really need to work with version 0.12.2

early

+4
source share
3 answers

to establish

 $ sudo apt-get install ruby-dev build-essential 

or

 $ sudo apt-get install postgresql-client libpq5 libpq-dev $ sudo gem install pg 

Update

Below are the steps that I followed:

Install PostgreSQL and the development package

 $ sudo apt-get install postgresql-9.1 $ sudo apt-get install libpq-dev 

Configure a user that is the same as my Ubuntu login

 $ sudo su postgres -c psql postgres=# CREATE ROLE <username> SUPERUSER LOGIN; postgres=# \q 

Edit Gemfile

 # Remove gem 'sqlite3' gem 'pg' 

Change database.yml in the application directory

 development: adapter: postgresql encoding: unicode database: appname_development pool: 5 timeout: 5000 username: <username> password: test: adapter: postgresql encoding: unicode database: appname_test pool: 5 timeout: 5000 username: <username> password: 

Run batch installation

 $ bundle install 

Database and Migration Creation

 $ rake db:create:all $ rake db:migrate 

Here are the sources I used to help:
http://mrfrosti.com/2011/11/postgresql-for-ruby-on-rails-on-ubuntu/
http://railsless.blogspot.in/2012/05/howto-install-postgresql-in-ubuntu11.html

+6
source
 # add a --with-cflags option gem install --with-cflags="-O2 -pipe -march=native -w" 

or

 # change your user-level bundle config options for pg and run # bundle install within the project bundle config build.pg --with-cflags="-O2 -pipe -march=native -w" cd ${project_dir} bundle install 

Keep in mind that this will change ${HOME}/.bundle/config , so for each user working with the project, they will need to run this command on every computer on which they work.

This CFLAGS parameter overrides the current system-wide values, which include -Werror=format-security . I believe that a real fix would be to fix the pg pearl so that this flag is set, it does not matter, but I did not look at the code for pg.

+2
source

Look at the error message:

ERROR: while executing gem ... (Gem :: FilePermissionError) You do not have write permissions to the / var / lib / gems / 1.9.1 directory.

Are you sure you ran your command with sudo? This is a write transfer error.

-3
source

Source: https://habr.com/ru/post/1442723/


All Articles