ubuntu 12.04中环境变量设置
Persistent environment variables
So far we've only discussed ways set an environment variable value temporarily until the shell session in which it was set is closed. One may wonder if there is a way to somehow permanently set an environment variable to a certain value.
Note: The shell config files mentioned below are only meant to be read by particular shells and desktop environments and should not be used.
Session-wide environment variables
Environment variable settings that should affect just a particular user (rather than the system as a whole) should be set into:
~/.pam_environment - This file is specifically meant for setting a user's environment. It is not a script file, but rather consists of assignment expressions, one per line.
- PATH DEFAULT=${PATH}:${HOME}/MyPrograms
Note: Using .pam_environment requires a re-login in order to initialize the variables. Restarting just the terminal is not sufficient to be able to use the variables.
If you are using KDE, see the KDE User-base page on this topic.
Not recommended anymore:
~/.profile - In this file you can also place environment variable assignments, since it gets executed automatically by the DisplayManager during the start-up process desktop session as well as by the login shell when one logs-in from the textual console.
~/.bash_profile or ~/.bash_login - If one of these file exist, bash executes it rather than "~/.profile" when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default.
~/.bashrc - Because of the way Ubuntu currently sets up the various script files by default, this may be the easiest place to set variables in. The default configuration nearly guarantees that this file will be executed in each and every invocation of bash as well as while logging in to the graphical environment. The performance cost of this will be negligible; the overhead of forking and execing bash will massively dominate the small cost of setting a handful of variables.
System-wide environment variables
Environment variable settings that affect the system as a whole (rather than just a particular user) should not be placed in any of the many system-level scripts that get executed when the system or the desktop session are loaded, but into
/etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.
Not recommended:
/etc/profile - This file gets executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the DisplayManager when the desktop session loads. This is probably the file you will get referred to when asking veteran UNIX system administrators about environment variables. In Ubuntu, however, this file does little more than invoke the /etc/bash.bashrc file.
/etc/bash.bashrc - This is the system-wide version of the ~/.bashrc file. Ubuntu is configured by default to execute this file whenever a user enters a shell or the desktop environment.
Note: Any variables added to these locations will not be reflected when invoking them with a sudo command, as sudo has a default policy of resetting the Environment and setting a secure path (this behavior is defined in /etc/sudoers). As a workaround, you can use "sudo su" that will provide a shell with root privileges but retaining any modified PATH variables.
Note: When dealing with end-user/home desktop systems may be appropriate to place settings in the user's ~/.pam_environment files discussed above rather than the system-wide ones, since those files do not require one to utilize root privileges in order to edit and are easily moved between systems.
Note: Some systems now use an envvar.sh placed in the /etc/profile.d/ directory to set system wide environment strings.
ubuntu 12.04中环境变量设置的更多相关文章
- Ubuntu 下开发 Android 环境变量设置
-----------------------------------------------------ANDROID_SDK_HOME:/home/cmm/avds PATH:/home/cmm/ ...
- 如何在ubuntu 12.04 中安装经典的 GNOME桌面
这次介绍的是如何在ubuntu 12.04 中安装经典的 GNOME桌面,默认的 Ubuntu 12.04 默认unity桌面,一些用户不喜欢 Unity 桌面,所以想找回昔日的经典Gnome桌面. ...
- ubuntu 12.04修改环境变量PAT…
这里我只针对ubuntu 12.04进行了测试,由于不同的linux发行版本可能会有一些地方不一致,所以对于其他的linux发行版仅供参考. 1.直接在命令行里添加 我们先来看下下PATH的值 ec ...
- Ubuntu 16.04 root环境变量不生效问题解决方案
在Ubuntu 16.04中配置JDK环境变量,但是在切换到root时不生效 . 在/etc/profile中添加如下: export JAVA_HOME=/opt/java/jdk1..0_151 ...
- Ubuntu 12.04 安装Redis并设置主从复制
今天想在Ubuntu上安装一个Redis服务器并配置Master-Slave,一开始懒得连VPN就查了一些国内的文章,不知道是没有亲自验证过的转载文章,还是版本问题造成的,发现按照步骤都没能成功完成配 ...
- Linux 中环境变量设置
本文主要整理自以下博文: .bash_profile和.bashrc的什么区别及启动过程 linux环境变量设置方法总结(PATH/LD_LIBRARY_PATH) .bash_profile 和 . ...
- NS2安装过程中环境变量设置的问题(ns-2.35)
nam: Can't find a usable tk.tcl in the following directories: */ns-allinone-2.35/tcl8.5.10/library/t ...
- linux中环境变量设置
Linux下环境变量设置的三种方法: 如想将一个路径加入到$PATH中,可以像下面这样做: 只对当前的shell 起作用的环境变量 1.控制台中设置,不赞成这种方式,因为他只对当前的shell 起作用 ...
- 【Mac】-NO.161.Mac.1 -【MacOS 中环境变量设置 zsh: command not found: xxx】
Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...
随机推荐
- FFmpeg命令添加视频字幕
FFmpeg添加字幕 首先需要科普下.vob,mkv等格式文件以流的形式存储字幕,而mp4不支持这种方式.如果希望生成带字幕的mp4文件,只能将字幕“烧录”到视频中. 也就是说我们需要将字幕流与视频流 ...
- MySQL查看和修改wait_timeout
1.全局查看wait_timeout值 mysql> show global variables like 'wait_timeout'; 2.修改全局wait_timeout值 set glo ...
- 解决Sping 框架 Controller@Value获取不到值
原因:要获取 int.properties 中的数据 但是 一直拿不到值 如下代码 使用这种方式注入 *.properties文件 <!-- 引入配置文件 --> <context: ...
- C# : 连接SDE空间数据库时出错
1.SDE认证问题:使用ArcGIS.KeyGen.exe生成一个epp文件方法:-->server-->All-->拷贝并保存为*.epp文件.认证时加载该文件即可认证完毕.2.实 ...
- 【剑指Offer面试题】 九度OJ1510:替换空格
c/c++ 中的字符串以"\0"作为结尾符.这样每一个字符串都有一个额外字符的开销. 以下代码将造成内存越界. char str[10]; strcpy(str, "01 ...
- centos7下mysqldump+crontab自动备份数据库
1.创建文件夹(存放备份数据) mkdir /bak mkdir /bak/mysqldata 2.编写脚本 vi /usr/sbin/bakmysql.sh 脚本内容如下 DATE=`date +% ...
- 关闭危害的端口DOS命令(转载)
rem ipseccmd -w REG -p "HFUT_SECU" -r "Block UDP/137" -f *+0:137:UDP -n BLOCK -x ...
- mysql innodb的重要组件
innodb包涵如下几个组件 一.innodb_buffer_pool: 1 它主要用来缓存数据与索引(准确的讲由于innodb中的表是由聚集索引组织的,所以数据只不是过主键这个索引的叶子结点). 二 ...
- 安卓-启动下一个Activity
Intent intent = new Intent(NotebookActivity.this, MessageActivity.class); startActivity(intent); 通过意 ...
- vue的路由使用
1). 安装 vue-router npm install vue-router --save 2). 新建路由配置 安装成功后,在 src 新建 router 文件夹,然后新建 index.js 文 ...