Learn how to install CodeQL on MacOS, Linux, and Windows. Follow the step-by-step guide to set up this powerful SAST tool for your projects.
Zoom image will be displayed
CodeQL is an open-source, powerful static analysis engine that helps developers identify vulnerabilities and bugs in their code. This guide will walk you through installing CodeQL on macOS, Linux, and Windows systems.
You have two options for installing CodeQL on macOS:
The simplest way to install CodeQL on macOS is by using Homebrew:
brew install codeqlsudo mv ~/Downloads/codeql /usr/local/3. Add CodeQL to your PATH.
echo 'export PATH="/usr/local/codeql:$PATH"' >> ~/.zshrc
source ~/.zshrcNote: To uninstall CodeQL, simply remove the directory and the PATH entry — sudo rm -rf /usr/local/codeql
Zoom image will be displayed
Note: After unzipping the CodeQL archive, you’ll see a folder named codeql that contains the actual codeql executable plus supporting files. Some people prefer to move just the codeql executable into /usr/local/bin so it’s immediately in the PATH. If you move the entire codeql folder (for example, to /usr/local/codeql), you’ll need to update your PATH to include /usr/local/codeql/ (as discussed above).
Follow these steps to install CodeQL on the Linux machine:
cd ~
wget https://github.com/github/codeql-cli-binaries/releases/download/v2.15.5/codeql-linux64.zip
unzip codeql-linux64.zip2. Move CodeQL to the appropriate location:
sudo mv codeql /opt/3. Add to your PATH:
echo 'export PATH="/opt/codeql:$PATH"' >> ~/.bashrc
source ~/.bashrc4. Once done, verify the installation:
codeql --versionInstallation on Windows requires a few PowerShell commands:
cd C:\codeql2. Download and extract CodeQL:
$version = "2.15.5"
Invoke-WebRequest -Uri "https://github.com/github/codeql-cli-binaries/releases/download/v$version/codeql-win64.zip" -OutFile "codeql.zip"
Expand-Archive -Path codeql.zip -DestinationPath . -Force3. Add CodeQL to your system PATH:
$oldPath = [Environment]::GetEnvironmentVariable('Path', 'Machine')
$newPath = $oldPath + ';C:\codeql\codeql'
[Environment]::SetEnvironmentVariable('Path', $newPath, 'Machine')Important: When modifying the system-wide Path environment variable on Windows, you need to run PowerShell as Administrator.
After installing CodeQL on any platform, verify the installation by running:
codeql --versionCodeQL is a versatile tool that can be installed on any major operating system. Whether you’re using macOS, Linux, or Windows, the installation process is straightforward and can be completed in just a few minutes. Once installed, you can verify your setup by running codeql --version in your terminal.