ruby-on-rails - 在 Windows 上运行的 Ubuntu bash 上设置 PostgreSQL

标签 ruby-on-rails postgresql ubuntu windows-subsystem-for-linux

我最近在作为 Linux 子系统运行在 Windows 上的 Ubuntu bash 上安装并设置了 Rails。我能够毫无问题地启动并运行 rails,并在我的 Windows C:/驱动器上创建一个新的 rails 应用程序。我尝试直接从 postgresql.org/downloads/windows 下载 PSQL网站但有一些问题所以我取消了,然后按照 this tutorial 的安装 PostgresQL 部分进行操作.唯一的问题是,之前取消的下载设置为监听默认端口5432,而且似乎一直占用着端口,因为第二次安装说必须使用端口5433。

编辑:原来的 PSQL 似乎已成功安装,因为它出现在我的程序列表中,我能够将其卸载,但确实收到错误警告,指出数据文件夹未被删除。卸载并只安装一个 PSQL 副本后,运行以下 sudo service postgresql start 时我仍然遇到相同的错误。

编辑 编辑:我完全卸载了 PSQL 的两个版本并重新安装了链接教程中的版本,它消除了我遇到的第二个错误。但是,我的“pg”gem 仍然没有捆绑安装。

完成后,我尝试将现有的 Rails 应用程序切换到 postgresql。我更新了 database.yml 文件并将“pg”gem 添加到我的 Gemfile 中。但是,我不能捆绑安装。当我尝试时,出现此错误:

Fetching pg 1.0.0
Installing pg 1.0.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/<user_profile>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/pg-1.0.0/ext
/home/<user_profile>/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20180717-4727-vex5p2.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=/home/<user_profile>/.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
        --without-pg-lib=${pg-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/<user_profile>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/pg-1.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/<user_profile>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/pg-1.0.0 for
inspection.
Results logged to
/home/<user_profile>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/pg-1.0.0/gem_make.out

An error occurred while installing pg (1.0.0), and Bundler cannot continue.
Make sure that `gem install pg -v '1.0.0' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  pg

编辑:下面已解决,引用上面的第二次编辑。

同样,当我尝试使用 sudo service postgresql start 从命令行启动 postgresql 时,我得到以下信息:

$ sudo service postgresql start
 * Starting PostgreSQL 9.5 database server                                                                            * The PostgreSQL server failed to start. Please check the log output:
2018-07-17 14:59:26 DST [4858-1] LOG:  could not bind IPv4 socket: Permission denied
2018-07-17 14:59:26 DST [4858-2] HINT:  Is another postmaster already running on port 5433? If not, wait a few seconds and retry.
2018-07-17 14:59:26 DST [4858-3] WARNING:  could not create listen socket for "localhost"
2018-07-17 14:59:26 DST [4858-4] FATAL:  could not create any TCP/IP sockets

有谁知道在我的环境中安装 PostgresQL 出了什么问题,以及如何让它在我的 Ubuntu shell 上成功运行?

最佳答案

找到了解决这些问题的方法。

问题 #1 - 'pg' gem 未安装 在 bash 中执行以下命令:

  1. sudo apt-get install libpq-dev
  2. gem 安装 pg
  3. 捆绑安装

问题 #2 - postgresql 无法在不崩溃的情况下启动

在计算机上卸载 PSQL 上的所有版本并重新安装一个。失败的安装和第二个版本正在共享它们的数据文件夹,导致我正在使用的安装出现错误。

关于ruby-on-rails - 在 Windows 上运行的 Ubuntu bash 上设置 PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51375117/

相关文章:

javascript - jquery.post() : how do i honor a redirect from the server?

ruby-on-rails - 使用 file_field 时 Railsnested_form_for 不起作用

ruby-on-rails - 部署后 Assets 不显示-heroku-rails 4

postgresql - 如何使用Golang的GORM从Postgresql数据库中获取数组?

sql - postgresql:对于给定的表名,模式名是什么?

ubuntu - 在 Ubuntu 中如何从 PHP 同时执行多个终端?

postgresql 接受动态 dns 主机?

mysqldump:写入时出现 errno 32

ruby-on-rails - 已激活 spring 1.4.0,但 Gemfile 需要 spring 1.3.3[错误]

python - PostgreSQL 日期时间类型的最佳数据类型