Centos | 添加环境变量 | /etc/profile ~/.bashrc ~/.bash_profile区别

本文介绍如何在Linux系统中通过编辑/etc/profile、~/.bashrc和~/.bash_profile文件来配置环境变量,包括针对所有用户和特定用户的环境变量设置方法,以及如何使修改立即生效。

vim /etc/profile

  • 推荐使用这种方法,因为所有用户的shell都有权使用这些环境变量,缺点是可能会给系统带来安全性问题。 这里是针对所有的用户的,所有的shell;
vim /etc/profile
# 使用source命令使修改立刻生效: 
source  /etc/profile

vi ~/.bashrc

修改.bashrc文件,这种方法更为安全,它可以把使用这些环境变量的权限控制到用户级别,这里是针对某一个特定的用户,如果需要给某个用户权限
使用这些环境变量,只需要修改其个人用户主目录下的.bashrc文件就可以了。

vi ~/.bashrc

source ~/.bashrc

vi ~/.bash_profile

每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.

vi ~/.bash_profile

source ~/.bash_profile
[root@centos-linux ~]# yum remove docker \ > anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority > anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority > anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority > anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority > docker-client \ 已加载插件:fastestmirror, langpacks 参数 docker 没有匹配 参数 docker-client 没有匹配 参数 没有匹配 不删除任何软件包 [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# docker-client-latest \ bash: docker-client-latest: 未找到命令... [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# docker-common \ bash: docker-common: 未找到命令... [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# docker-latest \ bash: docker-latest: 未找到命令... [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# docker-latest-logrotate \ bash: docker-latest-logrotate: 未找到命令... [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# docker-logrotate \ bash: docker-logrotate: 未找到命令... [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# anaconda-ks.cfg .cache/ initial-setup-ks.cfg .bash_logout .config/ .tcshrc .bash_profile .cshrc .xauth4ZflpI .bashrc .dbus/ .Xauthority [root@centos-linux ~]# docker-engine bash: docker-engine: 未找到命令...
最新发布
09-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值