3

I am following the diesel guide: LINK

When I try this:

cargo install diesel_cli --no-default-features --features postgres

I receive this error:

error: failed to compile `diesel_cli v1.4.1`, intermediate artifacts can be found at

and a note:

 = note: ld: library not found for -lpq
kometen
  • 6,536
  • 6
  • 41
  • 51
josedlujan
  • 5,357
  • 2
  • 27
  • 49
  • This means that cargo cannot locate the `pq` library for linking, You just need to install it: `yum install libpq` for centos, shouldn't be too difficult to locate the needed package for your machine – joshmeranda Dec 16 '21 at 18:13
  • Yes, sudo apt install libpq-dev but i cant... and i have java and path ok. msg: he operation couldn’t be completed. Unable to locate a Java Runtime that supports apt. Please visit http://www.java.com for information on installing Java. – josedlujan Dec 16 '21 at 20:29

3 Answers3

5

Solution:

The problem is cargo cannot locate the pq library, so i need to use:

 sudo apt install libpq-dev

This send me a error too:

The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt.
Please visit http://www.java.com for information on installing Java.

First I need to check Environment Variables, check your file:

% open -e .bash_profile

File content:

export JAVA_HOME=$(/usr/libexec/java_home)

But the error continue... so then that doesnt help me. I think sometimes just need this, in my case i install the elements by one bye with brew.

Second: Install postgreql

brew install postgresql

Third:Install libpq

brew install libpq  

Finally: Install diesel CLI

cargo install diesel_cli --no-default-features --features postgres
josedlujan
  • 5,357
  • 2
  • 27
  • 49
1

Once you have install

brew install postgresql
brew install libpq

Install diesel CLI

arch -x86_64 cargo install diesel_cli --no-default-features --features postgres
Nenjo Tsu
  • 11
  • 2
1

I've just encountered this issue, and didn't find the various answers around to be especially helpful. The crux of the problem for me was that, whilst it was obvious I needed to have libpq installed, it was not obvious that installing PosgreSQL is also mandatory. Moreover, brew install postgresql no longer works; you must specify which version to install.

Additionally, I also wanted Sqlite support, and had found no examples of installing both PG and Sqlite support without MySQL support.

What finally worked for me:

brew install libpq postgresql@15
brew link postgresql@15
cargo install diesel_cli --no-default-features --features postgres,sqlite
Richard Turner
  • 12,506
  • 6
  • 36
  • 37
  • 1
    This one solved it for me! Thank you! I executed the first 2 instructions and ran the `cargo install diesel ...`. I didn't need to do the export. – VaughnVoyage Aug 22 '23 at 07:32