How to work with OpenSSL for Rust within a Windows development environment How to work with OpenSSL for Rust within a Windows development environment windows windows

How to work with OpenSSL for Rust within a Windows development environment


  1. clone vcpkg
  2. open directory where you've cloned vcpkg
  3. run ./bootstrap-vcpkg.bat
  4. run ./vcpkg.exe install openssl-windows:x64-windows
  5. run ./vcpkg.exe install openssl:x64-windows-static
  6. run ./vcpkg.exe integrate install
  7. run set VCPKGRS_DYNAMIC=1 (or simply set it as your environment variable)


I had the same issue. Older version of the README of rust-openssl has the installation process for the Windows.

Precompiled Binaries

Download the precompiled binaries from here(non-light version), and install it. After the installation, set the environment variable OPENSSL_DIR to the installation path.

set OPENSSL_DIR=path\to\the\installation\dir

If you chose the Copy OpenSSL DLLs to: The OpenSSL binaries (/bin) directory option during the installation, add that directory to your path as well.

set PATH=%PATH%;path\to\the\installation\dir\bin

Then, you need to install the root certificate.

Using vcpkg

Install vcpkg by following the instructions on the README. After installation, run these commands.

vcpkg install openssl:x64-windowsset VCPKG_ROOT=c:\path\to\vcpkg\installation

Then, you need to install the root certificate.

Installing the root certificate

Download the cacert.pem file. Save it to somewhere (i.e C:\Program Files\OpenSSL-Win64\certs\cacert.pem), and add the SSL_CERT_FILE environment variable and point it to the file.

set SSL_CERT_FILE=C:\Program Files\OpenSSL-Win64\certs\cacert.pem


None of the other answers worked for me but I got it working with vcpkg and static linking. Here is what I did (I was trying to install wrangler, it worked after following the steps below and running cargo install wrangler).

  1. Install vcpkg (following the instructions from https://github.com/Microsoft/vcpkg#quick-start-windows). I ran this in a Visual Studio 2019 Developer Command Prompt (%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat") but I don't know if this is necessary.

    cd C:\git clone https://github.com/microsoft/vcpkgcd vcpkgvcpkg\bootstrap-vcpkg.bat
  2. From the same command prompt, install openssl

    vcpkg\vcpkg install openssl:x64-windows-static
  3. Install the CA certificates (as described by Fatih Karan's answer and the old README of the rust-openssl project)

    mkdir "C:\Program Files\OpenSSL-Win64\certs"curl --remote-name --time-cond "C:\Program Files\OpenSSL-Win64\certs\cacert.pem" -o "C:\Program Files\OpenSSL-Win64\certs\cacert.pem" https://curl.se/ca/cacert.pem
  4. In a command prompt in your Rust project (or any other directory if you don't have a Rust project and just need to cargo install something), set the following environment variables:

    set OPENSSL_NO_VENDOR=1set RUSTFLAGS=-Ctarget-feature=+crt-staticset SSL_CERT_FILE=C:\OpenSSL-Win64\certs\cacert.pem
    • OPENSSL_NO_VENDOR to 1: Instruct the openssl-sys crate to use a pre-compiled openssl library. If this is not set it will try to compile it and fail (because perl is typically not available on Windows).
    • RUSTFLAGS to -Ctarget-feature=+crt-static: Instruct the Rust compiler (or more precisely the linker invoked by the Rust compiler) to produce a statically linked binary. If this is missing, the vcpkg crate (which is used by the openssl-sys crate to find the pre-compiled openssl library) will use the vcpkg triplet x64-windows-static-md. It seems that this triplet does not exist for openssl. With this environment variable, vcpkg will use the triplet x64-windows-static and this worked for me.
    • SSL_CERT_FILE to the location of cacert.pem: You need the root certificates in this file to make secure connections to servers.