Mac上设置环境变量PATH

1、 打开终端Terminal。

2、 输入以下命令打开你的shell配置文件,比如bash或zsh。如果你使用的是bash,那么你需要编辑~/.bash_profile或者~/.bashrc文件;如果你使用的是zsh,那么你需要编辑~/.zshrc文件。

bash 复制代码
open -e ~/.bash_profile

或者

bash 复制代码
open -e ~/.zshrc

3、 在打开的配置文件中,你可以添加你的环境变量设置。例如,如果你想要添加一个名为MY_PATH的环境变量,并且它的值为/my/custom/path,你可以添加如下行:

bash 复制代码
export MY_PATH=/my/custom/path

4、 保存并关闭配置文件后,你需要让更改生效。这可以通过在终端中运行以下命令来实现:

bash 复制代码
source ~/.bash_profile

或者

bash 复制代码
source ~/.zshrc

5、 现在,你可以通过在终端中输入echo $MY_PATH来检查环境变量的值是否已经正确设置。

6、 如果你是在系统级别设置环境变量,那么需要管理员权限,可以使用sudo命令。

bash 复制代码
sudo source ~/.bash_profile

或者

bash 复制代码
sudo source ~/.zshrc
相关推荐
Wesleyblue6 小时前
Python解释器工作原理解析
命令行·环境变量·工作原理·脚本参数·python解释器
寒水馨8 小时前
macOS下载、安装PowerShell-v7.6.4(附安装包powershell-7.6.4-osx-arm64.pkg)
macos·自动化·跨平台·shell·脚本·命令行·powershell
星辰即远方1 天前
天气预报总结
macos·ios·objective-c·cocoa
xixiaoyunya1 天前
Mac远程访问新范式:基于80KM穿云箭的内网穿透技术实践
macos
秋雨梧桐叶落莳1 天前
计算器仿写总结
学习·macos·ios·objective-c·cocoa
寒水馨2 天前
macOS下载、安装uv-0.12.0(附安装包uv-aarch64-apple-darwin.tar.gz)
python·macos·rust·项目管理·包管理器·astral·pip替代
寒水馨2 天前
macOS下载、安装protobuf-v35.1(附安装包protoc-35.1-osx-universal_binary.zip)
macos·google·grpc·序列化·protobuf·protoc·数据交换
寒水馨2 天前
macOS下载、安装ripgrep-15.2.0(附安装包ripgrep-15.2.0-aarch64-apple-darwin.tar.gz)
macos·正则表达式·rust·ripgrep·rg·命令行搜索·代码搜索
起司喵喵3 天前
Flutter-MacOS桌面OS系统|flutter.+window_manager客户端OS模板
flutter·macos·策略模式
代码对我眨眼睛3 天前
macOS Google Chrome 常用快捷键
前端·chrome·macos