如何在Git Bash中使用Cursor CLI

作者:技术拾光时间:2026-08-02 16:17:18浏览:238

在Windows下,CursorCLI默认安装到本地应用数据目录的cursor-agent文件夹。下载官方脚本,修改两变量自定义安装路径,执行安装。安装后,在gitbash配置bash配置文件以使用agent命令。

下载

官方下载地址:cursor.com/cn/download

如何在Git Bash中使用Cursor CLI

官方文档:cursor.com/cn/docs/cli…

如何指定文件夹安装

在Windows环境下,安装Cursor CLI通常只需在PowerShell中执行一行命令:

 复制代码irm 'https://cursor.com/installwin32=true' | iex

默认安装路径是固定的,会被自动放置到%LOCALAPPDATA%\cursor-agent(即C:\Users\<用户名>\AppData\Local\cursor-agent)。若要指定自定义文件夹,方法很简单:下载官方脚本,手动修改其中的安装路径即可。

下载脚本的命令:

 复制代码# git bash
curl -o cursor-install.ps1 "https://cursor.com/installwin32=true"# powershell
irm "https://cursor.com/installwin32=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 "$TargetPath\dist-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 "$rootDir\cursor-agent.exe") {  
            Copy-Item -Path "$rootDir\cursor-agent.exe" -Destination "$rootDir\agent.exe" -Force  
        }  
        if (Test-Path "$rootDir\cursor-agent.cmd") {  
            Copy-Item -Path "$rootDir\cursor-agent.cmd" -Destination "$rootDir\agent.cmd" -Force  
        }  
        if (Test-Path "$rootDir\cursor-agent.ps1") {  
            Copy-Item -Path "$rootDir\cursor-agent.ps1" -Destination "$rootDir\agent.ps1" -Force  
        }  
    }  
    finally {  
        if (Test-Path $tempFile) {  
            Remove-Item $tempFile  
        }  
    }  
}  
function Initialize-CursorAgent {  
    ## initially set up the cursor-agent directory  
    ## Create %LocalAppData%\cursor-agent\versions  
    ## Add %LocalAppData%\cursor-agent to PATH  
    $agentPath = "$env:LOCALAPPDATA\cursor-agent"  
    $versionsPath = "$agentPath\versions"  
  
    # 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:LOCALAPPDATA\cursor-agent\versions" -Version $version  
Print-CursorAgentInstructions

注意脚本中第51行定义的$agentPath和第83行中Download-InstallPackage的$TargetPath,默认均指向$env:LOCALAPPDATA\cursor-agent。要修改安装路径,只需将这两处改为所需目录即可,例如:

 复制代码...
$agentPath = "D:\apps\CursorCLI"
...
Download-InstallPackage -UrlPrefix $downloadUrl -TargetPath "D:\apps\CursorCLI\versions" -Version $version
...

修改完成后,在PowerShell中执行下载的脚本:

 复制代码.\.cursor-install.ps1

安装成功后,即可在PowerShell中使用agent命令启动Cursor CLI。

在git bash中配置

安装脚本已自动将安装路径添加到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。