LoginSignup
1
0

More than 1 year has passed since last update.

gem pg をダウンロードしてバグを直したい

Posted at

現場railsの3章でbin/rails db:createをしようとした時です。
嬉しいことに、エラーにぶつかりました。どうやらgem pgがインストールされていないようです。

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

以下のコードを記入しても治らず

$ gem install pg
Building native extensions. This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

さらに

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

In Gemfile:
  pg

解決につながった記事および方法

こちらの記事を参考にして、以下のコマンドを入力したら治りました!libpq-devがないとpostgreサーバーにアクセスができないみたいですね。
https://qiita.com/Dexctersu/items/b2171f90f5bb82cf0888

$sudo apt install libpq-dev
$gem install pg -v 1.2.2
Building native extensions. This could take a while...
Successfully installed pg-1.2.2
1 gem installed

sudoコマンドを使うことで、root権限を持つユーザーの処理を代わりに行うことができるみたいです。
(引用「【 sudo 】コマンド――スーパーユーザー(rootユーザー)の権限でコマンドを実行する」https://www.atmarkit.co.jp/ait/articles/1611/28/news036.html)

aptコマンドはパッケージ管理に使用するコマンドみたいですね。

(引用「aptコマンドチートシート」https://qiita.com/SUZUKI_Masaya/items/1fd9489e631c78e5b007)

こちらにも解決方法が載っていましたが、いまいちvimの使い方が分からないので、宿題として持ち帰りますね。
https://qiita.com/miriwo/items/67681165b0a89218ee61

$ echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
$ source ~/.bash_profile

参考文献

解決につながった記事はこちら↓
https://qiita.com/Dexctersu/items/b2171f90f5bb82cf0888

「【 sudo 】コマンド――スーパーユーザー(rootユーザー)の権限でコマンドを実行する」https://www.atmarkit.co.jp/ait/articles/1611/28/news036.html
「aptコマンドチートシート」https://qiita.com/SUZUKI_Masaya/items/1fd9489e631c78e5b007

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0