Build wireguard-go from source
masterTo build the project, you must have the latest version of Go installed. Clone the repository and use make to compile.
$ git clone https://git.zx2c4.com/wireguard-go
$ cd wireguard-go
$ makerepository·master·Indexed 26 days ago
https://github.com/wireguard/wireguard-goA userspace Go implementation of the WireGuard protocol compatible with Linux, macOS, Windows, FreeBSD, and OpenBSD. This documentation covers CLI usage for creating network interfaces, foreground and background execution, environment variable configuration (such as LOG_LEVEL and WG_TUN_FD), and building the project from source.
To build the project, you must have the latest version of Go installed. Clone the repository and use make to compile.
$ git clone https://git.zx2c4.com/wireguard-go
$ cd wireguard-go
$ makeTo create a WireGuard interface and fork the process into the background, run the command followed by the desired interface name (e.g., wg0).
Once running, you can configure the interface using standard tools like wg(8), ip(8), or ifconfig(8). To remove the interface, use ip link del <interface_name>. If your system does not support direct interface removal, you can shut down wireguard-go by removing its control socket: rm -f /var/run/wireguard/<interface_name>.sock.
$ wireguard-go wg0To run wireguard-go without forking to the background, use the -f or --foreground flag. This is useful for debugging or running within a process manager.
$ wireguard-go -f wg0To run wireguard-go with increased logging verbosity, set the LOG_LEVEL environment variable to debug.
LOG_LEVEL=debugThe wireguard-go CLI uses the following exit codes:
0: ExitSetupSuccess - Setup completed successfully.1: ExitSetupFailed - Setup failed.You can control the behavior of wireguard-go using the following environment variables:
| Variable | Description |
|---|---|
WG_TUN_FD | The file descriptor of an existing TUN device. If set, wireguard-go will use this instead of creating a new one. |
WG_UAPI_FD | The file descriptor of an existing UAPI socket. If set, wireguard-go will use this instead of opening a new one. |
WG_PROCESS_FOREGROUND | Set to 1 to force the process to run in the foreground (prevents daemonization). |
LOG_LEVEL | Sets the logging verbosity. Supported values: verbose, debug, error, silent. (Defaults to error) |
The wireguard-go binary can be executed as a userspace WireGuard daemon. By default, it daemonizes itself unless the foreground flag is provided. You must specify an interface name.
Usage:
wireguard-go [-f|--foreground] INTERFACE-NAME
Arguments:
-f, --foreground: Run the process in the foreground. If not provided, the process will daemonize.INTERFACE-NAME: The name of the network interface to create.Version Check:
Use --version to print the current version and build information.
The current version of the wireguard-go implementation is exported as a constant named Version within the main package.
const Version = "0.0.20250522"