# Cargo: error: failed to run custom build command for `openssl-sys v0.9.99` — Could not find directory of OpenSSL installation / pkg-config not found

**Code:** `failed to run custom build command for openssl-sys` · **Category:** Rust · **Seen on:** Rust, SSL, Linux

The `openssl-sys` crate can't find OpenSSL headers/libraries (or pkg-config) to link against.

## Meaning

Install the dev package: Debian/Ubuntu `sudo apt install pkg-config libssl-dev`, Fedora `openssl-devel`, Alpine `openssl-dev`, macOS `brew install openssl@3` and set `OPENSSL_DIR=$(brew --prefix openssl@3)`. Or avoid system OpenSSL: use `rustls` features (`reqwest = { default-features = false, features = ["rustls-tls"] }`) or the `vendored` feature of `openssl`.

## Common causes

- libssl-dev/pkg-config missing
- macOS OpenSSL not found (Homebrew path)
- Cross compiling without target OpenSSL
- OpenSSL 3 vs old crate version
- Musl/Alpine builds

## Quick fix

1. `sudo apt install pkg-config libssl-dev`
2. macOS: `export OPENSSL_DIR=$(brew --prefix openssl@3)`
3. Use rustls or `openssl = { version = "0.10", features = ["vendored"] }`

## Detailed fix by platform

### Linux

1. `sudo apt install -y pkg-config libssl-dev && cargo build`

## How to diagnose

1. **Package** — libssl-dev?
2. **Env** — OPENSSL_DIR?
3. **Alternative** — rustls/vendored?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/rust/openssl-sys-build-failed)
