4

我在 Ubuntu 12.04 上运行,我正在尝试在 Ruby 1.9.3p194 / Rails 3.2.3 上安装 pg gem v '0.12.2'。我已经安装了 libpq-dev 和 build-essential 但我仍然得到同样的错误:

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

我确实成功安装了最新版本的 pg gem,但我真的需要使用 0.12.2 版本

提前致谢

4

3 回答 3

6

安装

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

或者

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

更新

以下是我遵循的步骤:

安装 PostgreSQL 和开发包

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

设置一个与我的 Ubuntu 登录相同的用户

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

修改 Gemfile

# Remove gem 'sqlite3'
gem 'pg'

修改app目录下的database.yml

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:

运行捆绑安装

$ bundle install

创建数据库和迁移

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

以下是我用来帮助的资源:http:
//mrfrosti.com/2011/11/postgresql-for-ruby-on-rails-on-ubuntu/
http://railsless.blogspot.in/2012/05/howto -install-postgresql-in-ubuntu11.html

于 2012-10-29T11:25:12.133 回答
2
# add a --with-cflags option
gem install --with-cflags="-O2 -pipe -march=native -w"

或者

# 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

请记住,这将修改${HOME}/.bundle/config,因此对于每个使用该项目的用户,他们需要在他们正在使用的每台机器上运行该命令。

此 CFLAGS 选项将覆盖当前系统范围的值,其中包括-Werror=format-security. 我相信真正的解决方法是修复 pg gem,以便设置这个标志是无关紧要的,但我还没有查看 pg 的代码。

于 2013-01-23T15:54:31.387 回答
-3

看看错误信息:

错误:执行 gem ... (Gem::FilePermissionError) 您没有写入 /var/lib/gems/1.9.1 目录的权限。

你确定你用 sudo 运行你的命令吗?这是一个写权限错误。

于 2012-10-29T16:52:22.000 回答