更新Xcode命令行工具后,如何不关闭会话刷新Terminal/iTerm?
Hey there! I totally get why you don't want to interrupt that 7-hour upload—let's fix the tns build ios error without closing your active session. Here are a few actionable steps:
1. 手动更新Xcode命令行工具路径并刷新环境变量
First, check if your terminal is using the correct Xcode developer path:
xcode-select -p
If it doesn't return /Applications/Xcode.app/Contents/Developer, update it with:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
Then reload your shell's configuration to apply changes immediately (pick the one matching your shell):
- For Bash:
source ~/.bash_profile - For Zsh (default on newer macOS):
source ~/.zshrc
2. 初始化Xcode命令行工具会话
Sometimes Xcode needs a post-update initialization that doesn't require a terminal restart. Run this command to trigger it:
xcodebuild -runFirstLaunch
This will complete any setup steps the command line tools need, making the updated version available in your current session.
3. 手动导出DEVELOPER_DIR环境变量
NativeScript might rely on the DEVELOPER_DIR variable to locate Xcode tools. Export it directly in your current session:
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
After running this, try your tns build ios command again—it should pick up the updated tools.
处理前台运行的上传会话
If your upload is running in the foreground of your terminal, you can temporarily move it to the background to run the above commands:
- Press
Ctrl+Zto pause the upload. - Type
bgand hit Enter to resume it in the background. - Run the environment-fix commands listed above.
- If you want the upload back in the foreground, type
fgand hit Enter.
This won't interrupt the upload (it stays running in the same terminal session) and lets you refresh the Xcode tool environment.
Before re-running tns build ios, verify the fix by checking the Xcode version:
xcodebuild -version
It should show the latest version you installed—if it does, your NativeScript build should work now!
内容的提问来源于stack exchange,提问作者Hang Chen

