2017年12月10日 星期日

如何解決安裝 sql 相關 gem 時常常遇到的 error: Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

因為是用 Postgresapp 安裝的 postgres sql,所以常常 bundle install 的時候都會遇到

```
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
ㄔ (0.21.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.21.0'` succeeds before bundling.
```

這樣的問題,其實這問題就是 gem 找不到安裝好的 postgres,只要指定路徑就行


如果 postgresapp 是最新版本的,那麼路徑就是

```
/Applications/Postgres.app/Contents/Versions/latest/bin
```

只要把 .zshrc 加上一段

```
PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
```

理論上再 bundle install 就可以了。




如果 postgresapp 不是最新版本的話就 cd 進去看看就行了

```
cd /Applications/Postgres.app/Contents/Versions
```

照上述的步驟設定好路徑就行了

手動一點的話也可以這樣:

```
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
```

happy coding


reference:

https://stackoverflow.com/questions/20754081/an-error-occurred-while-installing-pg-0-17-1-and-bundler-cannot-continue


沒有留言:

張貼留言