How to build OpenVPN from source

OpenVPN is widely used cross-platform VPN software, originally written by James Yonan in 2001, and now available for Linux, Windows, macOS, Android, iOS, and other platforms.

Here is how to build OpenVPN from source on a Linux server and a Windows client.

The OpenVPN source code for the current release is stored at https://github.com/OpenVPN/openvpn.

The source code for this release and previous releases is stored at https://openvpn.net/community-downloads.

Determine which release you will build.

Our examples use release 2.6.6.

Linux

  1. Download the OpenVPN compressed tarball from https://openvpn.net/community-downloads. In our example:
1
wget https://swupdate.openvpn.org/community/releases/openvpn-2.6.6.tar.gz
1
tar -xf openvpn-2.6.6.tar.gz
  1. Install the prerequisites for the build:
1
apt install -y build-essential libssl-dev iproute2 liblz4-dev liblzo2-dev libpam0g-dev libpkcs11-helper1-dev libsystemd-dev resolvconf pkg-config autoconf automake libtool libcap-ng-dev
  1. Build and install OpenVPN:
1
cd openvpn-2.6.6
1
autoreconf -i -v -f
1
./configure --enable-systemd --enable-async-push --enable-iproute2
1
make
1
make install
  1. Do an initial check of the binary:
1
cd /usr/local/sbin
1
./openvpn --version

Windows

  1. Install Git from https://git-scm.com/download/win.

  2. Install Visual Studio 2022 community edition from https://visualstudio.microsoft.com/vs/community.

  3. Visit https://openvpn.net/community-downloads and download the OpenVPN source archive version 2.6.6.

  4. Use 7-Zip to extract compressed tarball openvpn-2.6.6.tar.gz into openvpn-2.6.6.tar. Then extract openvpn-2.6.6.tar to give folder openvpn-2.6.6.

  5. Open Start > Visual Studio 2022 > Developer Command Prompt for VS 2022.

  6. In the Developer Command Prompt for VS 2022, install the Microsoft C/C++ dependency manager:

1
cd /d %USERPROFILE%
1
cd Downloads
1
git clone https://github.com/microsoft/vcpkg.git
1
cd vcpkg
1
bootstrap-vcpkg.bat
1
vcpkg integrate install
  1. In the Developer Command Prompt for VS 2022, build OpenVPN:
1
cd /d %USERPROFILE%
1
cd Downloads\openvpn-2.6.6
1
msbuild /p:Configuration=Release /p:Platform=x64
  1. In a regular Command Prompt window, do an initial check of the binary:
1
cd Downloads\openvpn-2.6.6\x64-Output\Release
1
.\openvpn.exe --version

Testing

  1. The easiest way to create a testbed on the server is to download and run the @angristan script:
1
curl -O https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh
1
chmod +x openvpn-install.sh
1
./openvpn-install.sh
  1. Prevent APT from upgrading the OpenVPN package that came from the repositories:
1
apt-mark hold openvpn
  1. Edit the systemd service file /etc/systemd/system/openvpn@.service. Change the executable from /usr/sbin/openvpn to /usr/local/sbin/openvpn.

  2. After saving the file, reload the systemd daemon:

1
systemctl daemon-reload
  1. Restart OpenVPN with your own binary:
1
systemctl restart openvpn@server
  1. On a Windows PC client, download the OpenVPN client configuration file that you generated on the server. Open PowerShell and issue the command:
1
scp root@YOUR.SERVER.IP.ADDRESS:xxxxxxxx.ovpn Downloads
  1. Download and run the standard OpenVPN installer from https://openvpn.net/community-downloads. There is no problem if it gives a message at the end of the install to say that there are no connection profiles (configuration files) yet.

  2. In the OpenVPN GUI, change the Settings so that it does not launch on user logon.

  3. Exit the OpenVPN GUI.

  4. Copy the xxxxxxxx.ovpn client configuration file from Downloads into Downloads\openvpn-2.6.6\x64-Output\Release.

  5. Run your binary by opening a Command Prompt with Run as Administrator and issuing the commands:

1
cd C:\Users\YOURUSERNAME\Downloads\openvpn-2.6.6\x64-Output\Release
1
.\openvpn.exe --config xxxxxxxx.ovpn