Cursor CLI 下载与安装指南
Cursor CLI官方下载地址:cursor.com/cn/download

Cursor CLI官方文档:cursor.com/cn/docs/cli…
如何自定义Cursor CLI安装文件夹
在Windows系统下,安装Cursor CLI通常只需在PowerShell中执行一行命令:
复制代码irm 'https://cursor.com/install?win32=true' | iex
但默认安装路径是固定的,会自动保存在%LOCALAPPDATA%cursor-agent(即C:Users<用户名>AppDataLocalcursor-agent)。那么,如何自定义安装路径呢?方法很简单:下载官方安装脚本,手动修改其中的路径变量即可。
下载安装脚本的命令:
复制代码# git bash
curl -o cursor-install.ps1 "https://cursor.com/install?win32=true"# powershell
irm "https://cursor.com/install?win32=true" -OutFile ".cursor-install.ps1"
下载后的脚本内容如下(仅展示关键部分):
复制代码$downloadUrl = 'https://downloads.cursor.com/lab/2026.07.16-899851b/'
$version = '2026.07.16-899851b'
function Get-Architecture {
# NB: We do it this way to protect against WOW64 redirection - i.e.
# if the user accidentally is in 32-bit or 64-bit Intel Powershell,
# we don't want to be fibbed to
$systemType = (Get-WmiObject Win32_ComputerSystem).SystemType
if ($systemType -like "*ARM64*") { return "arm64" } else { return "x64" }
}
function Download-InstallPackage {
param(
[string]$UrlPrefix,
[string]$TargetPath,
[string]$Version
)
$tempFile = "$TargetPath$([System.Guid]::NewGuid().ToString()).zip"
$architecture = Get-Architecture
$fullUrl = $UrlPrefix + "windows/$architecture/agent-cli-package.zip"
try {
Invoke-WebRequest -Uri $fullUrl -OutFile $tempFile
Expand-Archive -Path $tempFile -DestinationPath $TargetPath -Force
Rename-Item -Path "$TargetPathdist-package" -NewName $Version
# Copy all files that begin with 'cursor-agent' to the root dir
Get-ChildItem -Path "$TargetPath$Version" -Filter 'cursor-agent*' | Copy-Item -Destination "$TargetPath.."
# Create agent alias (primary command) for cursor-agent
$rootDir = "$TargetPath.."
if (Test-Path "$rootDircursor-agent.exe") {
Copy-Item -Path "$rootDircursor-agent.exe" -Destination "$rootDiragent.exe" -Force
}
if (Test-Path "$rootDircursor-agent.cmd") {
Copy-Item -Path "$rootDircursor-agent.cmd" -Destination "$rootDiragent.cmd" -Force
}
if (Test-Path "$rootDircursor-agent.ps1") {
Copy-Item -Path "$rootDircursor-agent.ps1" -Destination "$rootDiragent.ps1" -Force
}
}
finally {
if (Test-Path $tempFile) {
Remove-Item $tempFile
}
}
}
function Initialize-CursorAgent {
## initially set up the cursor-agent directory
## Create %LocalAppData%cursor-agentversions
## Add %LocalAppData%cursor-agent to PATH
$agentPath = "$env:LOCALAPPDATAcursor-agent"
$versionsPath = "$agentPathversions"
# If $agentPath exists, delete it
if (Test-Path $agentPath) {
Remove-Item -Recurse -Force $agentPath
}
New-Item -ItemType Directory -Path $agentPath -Force | Out-Null
New-Item -ItemType Directory -Path $versionsPath -Force | Out-Null
# Add to PATH
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($currentPath -notlike "*$agentPath*") {
[Environment]::SetEnvironmentVariable("PATH", "$currentPath;$agentPath", "User")
}
# Add to current shell PATH
if ($env:PATH -notlike "*$agentPath*") {
$env:PATH = "$env:PATH;$agentPath"
}
}
function Print-CursorAgentInstructions {
Write-Host "Start using Cursor Agent:"
Write-Host " agent"
Write-Host ""
Write-Host ""
Write-Host "Happy coding!"
Write-Host ""
}
Initialize-CursorAgent
Download-InstallPackage -UrlPrefix $downloadUrl -TargetPath "$env:LOCALAPPDATAcursor-agentversions" -Version $version
Print-CursorAgentInstructions
注意脚本中第51行和第83行分别定义了$agentPath和Download-InstallPackage中的$TargetPath,默认均指向$env:LOCALAPPDATAcursor-agent。如需更改安装路径,直接将这两个变量修改为你期望的目录即可,例如:
复制代码...
$agentPath = "D:appsCursorCLI"
...
Download-InstallPackage -UrlPrefix $downloadUrl -TargetPath "D:appsCursorCLIversions" -Version $version
...
修改完成后,在PowerShell中执行下载的脚本即可:
复制代码.cursor-install.ps1
安装成功后,即可在PowerShell中使用agent命令启动Cursor CLI。
在Git Bash中配置Cursor CLI
安装脚本已经自动将安装路径添加到Windows环境变量中,因此理论上在Git Bash中直接运行agent.cmd即可使用。但问题在于,Git Bash默认不会读取Windows的PATHEXT环境变量,因此直接输入agent命令不会生效。
解决方案非常简单:在~/.bash_profile文件中添加一个别名即可:
复制代码alias agent='<安装路径>/agent.cmd'
# 例如:alias agent='/d/apps/CursorCLI/agent.cmd'
保存后,重新启动Git Bash,即可愉快地使用agent命令调用Cursor CLI。
