Installing libwebsockets (LWS) directly from GitHub uses standard CMake.
Step-by-Step Installation (Linux / macOS)
1. Install System Dependencies
LWS requires cmake, gcc/g++ (or clang), and SSL headers (OpenSSL/WolfSSL).
Ubuntu / Debian:
Fedora / RHEL / CentOS:
macOS (Homebrew):
2. Clone the Official Repository
Clone the repository and check out a stable release tag (recommended over main for production reliability):
3. Build and Install via CMake
LWS requires an out-of-source build directory:
Key CMake Options (Customizing Your Build)
You can pass extra flags to cmake .. depending on your requirements:
| Flag | Default | Description |
-DLWS_WITH_SSL=ON | ON | Enables OpenSSL/TLS support. |
-DLWS_WITH_HTTP2=ON | ON | Enables HTTP/2 protocol support. |
-DLWS_WITH_MINIMAL_EXAMPLES=ON | OFF | Builds sample client/server code in the build folder. |
-DLWS_MAX_SMP=8 | 1 / Auto | Sets maximum SMP thread count for multi-threaded service loops. |
-DCMAKE_INSTALL_PREFIX=/usr | /usr/local | Changes the default installation target directory. |
Verifying the Installation
To verify your installation, create a minimal C test file (test.c):
Compile and run it: