0
点赞
收藏
分享

微信扫一扫

MAC - .bash_profile解密

黎轩的闲暇时光 2022-04-17 阅读 68

目录标题

前言

1、我们都知道以“.”开头的文件都属于隐藏文件,所以./bash_profile属于【隐藏文件】;
2、./bash_profile文件的作用是配置【系统环境变量】,位于【home】目录下;
3、cd ~:进入当前的home目录
在这里插入图片描述

一、如何打开./bash_profile文件

方式1:cat 命令

在这里插入图片描述
如果想要修改,可以使用vim ~/./bash_profile命令。

方式2:open 命令

在这里插入图片描述

二、如何修改./bash_profile配置文件

方式一:进入./bash_profile并修改配置文件

1、启动Terminal

2、进入当前用户的home目录

  • 在cmd输入 cd ~
    在这里插入图片描述

3、编辑.bash_profile文件

  • 在cmd输入open -e .bash_profile

这时./bash_profile就会打开
可以在后面加入要写入的环境变量(注意:从后往前读,注意覆盖)
在这里插入图片描述

4、保存文件,关闭.bash_profile

5、更新刚配置的环境变量

  • cmd输入source .bash_profile 保存,使其配置文件生效

6、cmd 输入echo $PATH可查看配置结果

方式二:命令行方式修改配置文件

1、在命令行中输入

echo 'export PATH=/Users/chenmingsong/myspace/install/mongodb/bin:$PATH'>>~/.bash_profile

在这里插入图片描述

2、查看环境变量

查看.bash_profile环境变量文件,发现多了一行mongdb配置:
在这里插入图片描述

3、更新刚配置的环境变量

  • cmd输入source .bash_profile 保存,使其配置文件生效

三、环境变量配置规则

方式1

export M2_HOME=/usr/local/apache-maven-3.3.9
export PATH=$PATH:$M2_HOME/bin

export GRADLE_HOME=/usr/local/Cellar/gradle/4.10.2
export PATH=$PATH:$GRADLE_HOME/bin

export MONGO_HOME=/usr/local/Cellar/mongodb@3.4/3.4.18
export PATH=$PATH:$MONGO_HOME/bin

export RABBIT_HOME=/usr/local/Cellar/rabbitmq/3.7.15
export PATH=$PATH:$RABBIT_HOME/sbin

方式2:
在这里插入图片描述

举报

相关推荐

0 条评论