路径在linux里设置永久环境变量的方法(Method for setting permanent environment variables in Linux)

linux设置环境变量  时间:2021-01-27  阅读:()

在linux里设置永久环境变量的方法Method for settingpermanent environment variables in Linux

Method for setting environment variables in Linux

In general, when you configure cross compile tool chains, youneed to specify the path of the build tool, which you need toset the environment variable. For example, my mips-linux-gcccompiler, in the /opt/au1200_rm/build_tools/bin directory,build_tools is my compilation tool, and there are three waysto set up environment variables:

1, use the export command directly:

#export PATH=$PATH:/opt/au1200_rm/build_tools/bin

Check to see if it is set up and check with the command export:[root@localhost bin]# export

Declare -x BASH_ENV= "/root/.bashrc""

Decl are -x G_BROKEN_FI LENAMES= "1""

Declare -x HISTSIZE= "1000""

Declare -x HOME= "/root""

Declare -x HOSTNAME= "localhost. localdomain""

Declare -x INPUTRC= "/etc/inputrc""

Declare -x LANG= "zh_CN.GB18030""

D ec l are -x LANGUAGE= "zh_CN.GB 18030:zh_CN.GB2312:zh_CN""

Declare -x LESSOPEN= "|/usr/bin/lesspipe. sh%s""

Declare -x LOGNAME= "root""

Declare-x LS_COLORS=no=00:f i=00:di=01 "; 34:ln=01 ; 36:pi=40;

33:so=01; 35:bd=40; 33; 01 :cd=40; 01:or=01; 33; 05; 37; 05; 37;

41:mi=01; 41:ex=01; 32:*. cmd=01 ; 32:*.exe=01; 32:*. com=01 ;

32:*.btm=01; 32:*.bat=01; 32:*. sh=01 ; 32:*.csh= 01;

32:*.tar=01; 31:*.tgz=01; 31 :*.arj=01; 31:*.taz=01;

31:*. lzh=01; 31:*.zip=01; 31 :*. z=01; 31 :*.Z=01; 31:*.gz=01;

31:*.bz2=01; 31:*.bz=01; 31:*.tz=01; 31 :*.rpm=01 ;

31:*.cpio=01; 31 :*. jpg=01 ; 35:*.gif=01; 35:*.bmp=01 ;

35:*.xbm=01; 35:*.Xpm=01; 35:*.png=01; 35:*.t if=01; 35"Declare -x MAIL= "/var/spool/mail/root""

Declare -x OLDPWD= "/opt/au1200_rm/build_tools""

Declare -x PATH=

"/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/opt/au1200_rm/build_tools/bin""

Declare -x PWD= "/opt/au1200_rm/build_tools/bin""

Declare -x SHELL= "/bin/bash""

Declare -x SHLVL= "1""

Declare -x SSH_ASKPASS=

"/usr/libexec/openssh/gnome-ssh-askpass""

Declare -x SSH_AUTH_SOCK= "/tmp/ssh-XX3LKWhz/agent.4242""Declare -x SSH_CLIENT= "10.3.37. 152 223622""

Declare -x SSH_CONNECTION= "10.3. 37. 152 2236 10. 3.37. 186 22""

Declare -x SSH_TTY= "/dev/pts/2""

Declare -x TERM= "Linux""

Declare -x USER= "root""

Declare -x USERNAME= "root""

As you can see, the environment variables are set, and the PATHalready has the path of the compiler I want to add.

2, modify the profile file:

#vi /etc/profile

Join in it:

Export PATH= "$PATH:/opt/au1200_rm/build_tools/bin""

3. modify the.Bashrc file:

# VI /root/.bashrc

Join in it:

Export PATH= "$PATH:/opt/au1200_rm/build_tools/bin""

The latter two methods generally needtobere writtento effectthe system and can be tested by the echo command at last:# ec ho $PATH

Take a look at the output, which is already had /my_new_paththis path?.

-----------------------------------------------------------

-----------------------------------------------------------

"/ bin" 、 "/ sbin" 、 "/ usr / bin" 、 "/ usr / sbin" 、 "/usr / local / bin"等路径已经在系统环境变量中了,如果可执行文件在这几个标准位置,在终端命令行输入该软件可执行文件的文件名和参数(如果需要参数) , 回车即可.

如果不在标准位置,文件名前面需要加上完整的路径.不过每次都这样跑就太麻烦了,一个"一劳永逸"的办法是把这个路径加入环境变量.命令"path = $path:路径"可以把这个路径加入环境变量,但是退出这个命令行就失效了.要想永久生效,需要把这行添加到环境变量文件里.有两个文件可选: "/ etc / profile"和用户主目录下的".bash_ profile ' , ' / etc / profile"对系统里所有用户

都有效,用户主目录下的".bash只对这个用户有效_ profile"."path = $path:路径1:路径2: :路径n",意思是可执行文件的路径包括原先设定的路径,也包括从"路径1"到"路径n的所有路径.当用户输入一个一串字符并按回车后, shell会依次在这些路径里找对应的可执行文件并交给系统核心执行.那个" $"path"表示原先设定的路径仍然有效,注意不要漏掉.某些软件可能还有"path"以外类型的环境变量需要添加,但方法与此相同,并且也需要注意"

注意,与dos /window不同, un ix类系统环境变量中路径名用冒号分隔,不是分号.另外,软件越装越多,环境变量越添越多, 为了避免造成混乱,建议所有语句都添加在文件结尾,按软件的安装顺序添加.

格式如下() :

#软件名-版本号path = $path: : : :路径n路径1路径2. . .

其他环境变量= $其他环境变量: . . .

在"profile"和".bash中_profile", "#"是注释符号, 写在这里除了视觉分隔外没有任何效果.

设置完毕,注销并重新登录,设置就生效了.如果不注销,直接在shell里执行这些语句,也能生效,但是作用范围只限于执行了这些语句的shell.

相关的环境变量生效后,就不必老跑到软件的可执行文件目录里去

操作了.

SugarHosts糖果主机六折 云服务器五折

也有在上个月介绍到糖果主机商12周年的促销活动,我有看到不少的朋友还是选择他们家的香港虚拟主机和美国虚拟主机比较多,同时有一个网友有联系到推荐入门的个人网站主机,最后建议他选择糖果主机的迷你主机方案,适合单个站点的。这次商家又推出所谓的秋季活动促销,这里一并整理看看这个服务商在秋季活动中有哪些值得选择的主机方案,比如虚拟主机最低可以享受六折,云服务器可以享受五折优惠。 官网地址:糖果主机秋季活动促...

Sharktech$129/月,1Gbps不限流量,E5-2678v3(24核48线程)

Sharktech最近洛杉矶和丹佛低价配置大部分都无货了,只有荷兰机房还有少量库存,商家又提供了两款洛杉矶特价独立服务器,价格不错,CPU/内存/硬盘都是高配,1-10Gbps带宽不限流量最低129美元/月起。鲨鱼机房(Sharktech)我们也叫它SK机房,是一家成立于2003年的老牌国外主机商,提供的产品包括独立服务器租用、VPS主机等,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹等,主...

georgedatacenter:美国VPS可选洛杉矶/芝加哥/纽约/达拉斯机房,$20/年;洛杉矶独立服务器39美元/月

georgedatacenter怎么样?georgedatacenter这次其实是两个促销,一是促销一款特价洛杉矶E3-1220 V5独服,性价比其实最高;另外还促销三款特价vps,大家可以根据自己的需要入手。georgedatacenter是一家成立于2019年的美国vps商家,主营美国洛杉矶、芝加哥、达拉斯、新泽西、西雅图机房的VPS、邮件服务器和托管独立服务器业务。georgedatacen...

linux设置环境变量为你推荐
天气预报哪个好用哪个最准确手机上的天气预报软件,哪个最准,最好用?免费阅读小说app哪个好求一个看书比较好的APP江门旅游景点哪个好玩的地方江门有哪些旅游景点,江门哪里好玩手机杀毒软件哪个好什么手机杀毒软件最好用?ps软件哪个好什么PS软件好播放器哪个好手机本地视频播放器哪个好用美国国际集团世界五百强企业前五十名是哪些?美国国际东西方大学明尼苏达大学(是莫瑞斯分校)和美国东北大学 应该去哪一个 是这个方面的专家回答啊!有偏见性的不要说!牡丹江教育云空间登录请问一下校园云空间的登录方式有哪些?空间登录页面怎样用网页登录到自己的QQ空间?
域名是什么 服务器租用托管 免费域名申请 花生壳域名贝锐 堪萨斯服务器 xen 绍兴高防 三拼域名 警告本网站美国保护 腾讯云分析 asp免费空间申请 双十一秒杀 空间合租 香港新世界中心 备案空间 路由跟踪 独立主机 畅行云 注册阿里云邮箱 阵亡将士纪念日 更多