Semgrep

Launch your CLI, and follow the instructions on the Scan a project on your machine page. For your convenience, the same information is presented below, along with instructions for Windows users.

  • macOS

  • Linux

  • Windows (beta)

  • Docker

i. Install the Semgrep CLI and confirm the installation:

# preferred: install through pipx (https://pipx.pypa.io/stable/how-to/install-pipx/)
pipx install semgrep

# preferred: install through uv (https://docs.astral.sh/uv/)
uv tool install semgrep

# best-effort: install through homebrew (maintained on a best-effort basis; often lags behind the latest release)
brew install semgrep

# confirm installation succeeded by printing the currently installed version
semgrep --version

NOTEpipx and uv are the preferred installation methods. The Homebrew formula is maintained on a best-effort basis and often lags behind the latest release.Homebrew users: ensure that you’ve added Homebrew to your PATH.

ii. Log in to your Semgrep account. Running this command launches a browser window, but you can also use the link that’s returned in the CLI to proceed:

semgrep login

iii. In the Semgrep CLI login, click Activate to proceed.iv. Return to the CLI, navigate to the root of your project, and run your first scan:

semgrep ci

i. Install the Semgrep CLI and confirm the installation:

# install through pipx (https://pipx.pypa.io/stable/how-to/install-pipx/)
pipx install semgrep

# or, install through uv (https://docs.astral.sh/uv/)
uv tool install semgrep

# confirm installation succeeded by printing the currently installed version
semgrep --version

ii. Log in to your Semgrep account. Running this command launches a browser window, but you can also use the link that’s returned in the CLI to proceed:

semgrep login

iii. In the Semgrep CLI login, click Activate to proceed.iv. Return to the CLI, navigate to the root of your project, and run your first scan:

semgrep ci

i. Download and install Python. Make sure to check the box to add python.exe to the PATH, otherwise you will have difficulty running Semgrep.ii. Configure your system to run Python with UTF-8 text encodings by default. In PowerShell, run:

[System.Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'User')

iii. Install the Semgrep CLI and confirm the installation. In PowerShell, run:

# install through pipx (https://pipx.pypa.io/stable/how-to/install-pipx/)
pipx install semgrep

# or, install through uv (https://docs.astral.sh/uv/)
uv tool install semgrep

# confirm installation succeeded by printing the currently installed version
semgrep --version

iv. Log in to your Semgrep account. Running this command launches a browser window, but you can also use the link that’s returned in the CLI to proceed:

semgrep login

v. In the Semgrep CLI login, click Activate to proceed.vi. Return to the CLI, navigate to the root of your project, and run your first scan:

semgrep ci

i. Pull the latest image and confirm the version:

docker pull semgrep/semgrep

# confirm version
docker run --rm semgrep/semgrep semgrep --version

ii. For users running Docker on macOS or Linux Docker:a. Log in to your Semgrep account (running this command will launch a browser window, but you can also use the link that’s returned in the CLI to proceed):

docker run -it semgrep/semgrep semgrep login

b. In the Semgrep CLI login, click Activate to proceed. Return to the CLI and copy the login token that’s shown.c. Navigate into the root of your project, and run your first scan. Be sure to substitute YOUR_TOKEN with the login token value you copied in the previous step:

docker run -e SEMGREP_APP_TOKEN=YOUR_TOKEN --rm -v "${PWD}:/src" semgrep/semgrep semgrep ci

The provided -v option mounts the current directory into the container to be scanned. Navigate into a different project or provide a specific local directory in the command to scan a different project.iii. For users running Docker on Windows:a. Log in to your Semgrep account (running this command will launch a browser window, but you can also use the link that’s returned in the CLI to proceed):

docker run -it semgrep/semgrep semgrep login

b. In the Semgrep CLI login, click Activate to proceed. Return to the CLI, and copy the login token that’s shown.c. Navigate into the root of your project, and run your first scan. Be sure to substitute YOUR_TOKEN with the login token value you copied in the previous step:

docker run -e SEMGREP_APP_TOKEN=YOUR_TOKEN --rm -v "%cd%:/src" semgrep/semgrep semgrep ci

The provided -v option mounts the current directory into the container to be scanned. Navigate into a different project or provide a specific local directory in the command to scan a different project.

Read the original on docs.semgrep.dev ↗