在git bash中使用Cursor CLI

下载

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

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

如何指定文件夹安装

一般来讲,在Windows环境下,Cursor CLI的安装方式是在powershell下运行:

powershell 复制代码
irm 'https://cursor.com/install?win32=true' | iex

但默认情况下无法指定文件夹安装,会自动安装在%LOCALAPPDATA%\cursor-agent(一般为 C:\Users\<用户名>\AppData\Local\cursor-agent文件夹)。我们需要做的就是将官方的运行脚本下载下来,并更改其中的安装路径。

将文件下载下来:

arduino 复制代码
# 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"

下载下来的脚本是这样的:

php 复制代码
$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行和83行:

bash 复制代码
...
$agentPath = "$env:LOCALAPPDATA\cursor-agent"
...
Download-InstallPackage -UrlPrefix $downloadUrl -TargetPath "$env:LOCALAPPDATA\cursor-agent\versions" -Version $version
...

$env:LOCALAPPDATA\cursor-agent改成期望的路径(或者直接丢给AI改),比如:

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

然后在powershell下安装即可:

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

安装成功后即可在powershell下通过agent命令即可开始使用Cursor CLI。

另一种方法

AI还说可以"用 NTFS 目录联接(Junction)做「软重定向」",将默认安装路径指向计划安装的地方即可,后续升级时也可以直接运行官方命令。

但我觉得在脚本里写死路径更有安全感,如果后续官方脚本修改了默认安装路径,更新时软重定向就失效了。

在git bash中配置

其实执行安装脚本时,脚本已经将安装路径加到了Windows的环境变量中,直接运行agent.cmd命令就可以在git bash环境下使用了,但git bash默认不会读Windows的PATHEXT环境变量,故无法直接通过agent命令打开Cursor CLI。

需要配置一下~/.bash_profile文件,在其中添加:

ini 复制代码
alias agent='<安装路径>/agent.cmd'
# 如:alias agent='/d/apps/CursorCLI/agent.cmd'

Windows下, git bash 默认不会加载 ~/.bashrc ,若习惯在 ~/.bashrc 下配置环境,可以在 ~/.bash_profile 中手动添加一行 source ~/.bashrc 。(学习自:Windows下的Git Bash配置,提升你的终端操作体验 - Achuan-2的文章 - 知乎

然后就可以愉快地在git bash下使用agent命令打开Cursor CLI了。

相关推荐
Nightwatchman2 小时前
AI 编程:追不完的工具,理得清的问题
ai编程·aiops·cursor
撑伞的鱼99373 天前
C++开发用什么AI编程工具效果好?2026年实测横评(附选型指南)
开发语言·c++·ai编程·cursor
旋生万物10 天前
五条几何公理重构元素周期表:从量子力学到螺旋拓扑的降维(AI 编程时代的微观启示)
重构·ai编程·代码审计·cursor·ai agent·mcp协议·claudecode
武雄(小星Ai)11 天前
2026 AI编程工具横评:Trae、Cursor、Copilot、Claude Code实测对比
ai·copilot·cursor·编程工具·trae·claude code·对比评测
咖啡星人k11 天前
AI 编程工具集体变脸:Cursor 漏洞、TRAE 限额、Claude Code 数据收集风波
人工智能·安全·microsoft·cursor·trae·ai编程工具
csdn_aspnet15 天前
如何将 Cursor MCP 与 VS Code 连接
vscode·cursor·mcp·composio
思码梁田15 天前
CSS cursor 属性全解析:从“小手“开始,玩转鼠标光标
前端·css·计算机外设·cursor·pointer
武雄(小星Ai)17 天前
2026年7月 AI 编程工具横评:Claude Code vs Cursor vs GitHub Copilot 实测对比
ai·开发工具·claude·cursor·对比评测
redreamSo17 天前
32 个 AI 编程工具的配置都放哪,这个仓库整理清楚了
ai编程·claude·cursor
唠点键盘之外的19 天前
10 Spring Boot + 大模型:Java 项目接入 AI 的三种姿势
java·spring boot·aigc·cursor