MacOS安装Delve时遇security: SecKeychainSearchCopyNext错误求助
Hey there! I’ve run into this exact issue before setting up Delve on macOS—let’s get this sorted out for you. The error pops up because Homebrew’s automated attempt to generate the self-signed certificate (required for debugging on macOS) is failing to interact properly with your keychain. Here’s how to fix it step by step:
Step 1: Manually Create the Required Certificate
The simplest way to bypass the brew-generated certificate glitch is to make the certificate yourself via Keychain Access:
- Open Keychain Access (find it quickly with Cmd+Space Spotlight search)
- Select the System keychain from the left sidebar
- Go to
File > New Certificate Assistant > Create a Certificate - Fill in these critical details:
- Name:
dlv-cert(this exact name is non-negotiable—Delve looks specifically for this certificate) - Identity Type: Self-Signed Root Certificate
- Certificate Type: Code Signing
- Check the box labeled "Let me override defaults", then click Continue
- Name:
- For all subsequent steps, just keep clicking Continue until you reach the "Specify a Location For The Certificate" screen—make sure System is selected, then click Finish
- Locate the
dlv-certcertificate in your System keychain, right-click it and select Get Info - Expand the Trust section, set "Code Signing" to Always Trust, then close the info window (you’ll need to enter your system password to confirm the change)
Step 2: Clean Up and Reinstall Delve
With the certificate properly in place, let’s reset the failed brew installation:
- First, clear out any leftover files from the incomplete install:
brew cleanup delve - Then re-run the original install command:
brew install go-delve/delve/delve
If Step 1 Fails: Use Command Line to Generate the Certificate
If the GUI method doesn’t resolve the issue, let’s generate the certificate directly via terminal:
- Generate the base certificate and key files:
(You can press Enter through all prompts—no need to fill in extra details like country or organization)openssl req -new -newkey rsa:2048 -x509 -days 3650 -nodes -out dlv-cert.pem -keyout dlv-cert.key - Combine the key and certificate into a single .p12 file:
cat dlv-cert.key dlv-cert.pem > dlv-cert.p12 - Import the file into your keychain:
security import dlv-cert.p12 -k ~/Library/Keychains/login.keychain-db -P "" -T /usr/bin/codesign - Mark the certificate as trusted:
security add-trusted-cert -d -r trustRoot -k ~/Library/Keychains/login.keychain-db dlv-cert.pem - Clean up the temporary files we created:
rm dlv-cert.* - Finally, re-run the brew install command as before.
Why This Happens
macOS requires debuggers to be code-signed to run safely, so Delve relies on a self-signed certificate for this purpose. The error you saw means Homebrew’s automated script couldn’t locate or access the correct keychain entry to create this certificate—manual creation bypasses that automated process and ensures the certificate is properly registered in your keychain.
内容的提问来源于stack exchange,提问作者Nic

