Linux添加环境变量的⼏种⽅法最近在安装ansible,安装后命令不到
[root@center ansible-2.7.5]# python setup.py install
安装后查看相关版本
[root@center ansible-2.7.5]# ansible --version
-bash: ansible: command not found
查看可执⾏⽂件⽬录为
[root@center ansible-2.7.5]# /usr/local/bin/ansible --version
ansible 2.7.5
config file = None
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/site-packages/ansible-2.7./ansible
executable location = /usr/local/bin/ansible
linux安装jdk环境变量python version = 2.7.8 (default, Jan 92019, 14:25:24) [GCC 4.8.520150623 (Red Hat 4.8.5-16)]
[root@center ansible-2.7.5]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
当前PATH 并没有/usr/local/bin,因此需要将/usr/local/bin添加到环境变量中
下⾯列出三种添加⽅法
1、直接⽤export命令:
export PATH=/usr/local/bin:$PATH
[root@center ansible-2.7.5]# echo $PATH
/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
但是这种⽅法只会对当前⽤户及当前命令⾏窗⼝⽣效,退出后就会丢失
2、编辑修改.bashrc⽂件:
vim /root/.bashrc
#在最后⼀⾏添上:
export PATH=/usr/local/bin:$PATH
这种⽅法只会对当前⽤户⽣效,需重启系统
3、编辑修改profile⽂件:
vim /etc/profile
export PATH=/usr/local/bin:$PATH
这种⽅法对所有⽤户⽣效,需重启系统
所以我们配置时需要结合1-2或者1-3
配置完之后再次执⾏ansible
[root@center ansible-2.7.5]# ansible --version
ansible 2.7.5
config file = None
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/site-packages/ansible-2.7./ansible
executable location = /usr/local/bin/ansible
python version = 2.7.8 (default, Jan 92019, 14:25:24) [GCC 4.8.520150623 (Red Hat 4.8.5-16)]

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。