在Ubuntu中哪里设置了PATH变量? [英] Where is PATH variable set in Ubuntu?

查看:57
本文介绍了在Ubuntu中哪里设置了PATH变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常有趣的问题,我在为Linux创建命令行应用程序工具时偶然发现.不幸的是,关于SO的答案隐藏在对其他问题无数的答案中,以至于我决定针对那些想要以编程方式修改PATH的人问另一个关于SO的问题.

This is a very interesting question that I stumbled upon when I was creating a command-line application tool for Linux. Unfortunately, the answer on SO is so hidden among the myriad answers to other questions that I decided to ask another question on SO for those who want to modify PATH programmatically.

推荐答案

GrzegorzŻur对另一个问题的回答精妙地抓住了它.不幸的是,它被隐藏在许多其他答案中.

Grzegorz Żur's answer to another question captures it brilliantly. Unfortunately it was hidden away among many other answers.

有多种方法可以做到这一点.实际解决方案取决于目的.

There are multiple ways to do it. The actual solution depends on the purpose.

变量值通常存储在分配列表中或在系统或用户启动时运行的Shell脚本会议.如果使用Shell脚本,则必须使用特定的Shell语法.

The variable values are usually stored in either a list of assignments or a shell script that is run at the start of the system or user session. In case of the shell script you must use a specific shell syntax.

  1. /etc/environment 唯一分配的列表.非常适合将系统范围的目录(例如/usr/local/something/bin )添加到 PATH 变量或定义 JAVA_HOME .
  2. /etc/xprofile 启动X Window系统会话时执行的Shell脚本.将为每个登录X Window的用户运行系统.对于有效的 PATH 条目,这是一个不错的选择每个用户都喜欢/usr/local/something/bin .该文件包含在其他脚本,因此请使用POSIX Shell语法而不是用户的语法外壳.
  3. /etc/profile /etc/profile.d/* Shell脚本.对于仅使用shell的系统,这是一个不错的选择.这些文件仅由外壳程序读取.
  4. /etc/< shell>.< shell> rc .Shell脚本.这是一个糟糕的选择,因为它是特定于单个shell的.
  1. /etc/environment List of unique assignments. Perfect for adding system-wide directories like /usr/local/something/bin to PATH variable or defining JAVA_HOME.
  2. /etc/xprofile Shell script executed while starting X Window System session. This is run for every user that logs into X Window System. It is a good choice for PATH entries that are valid for every user like /usr/local/something/bin. The file is included by other script so use POSIX shell syntax not the syntax of your user shell.
  3. /etc/profile and /etc/profile.d/* Shell script. This is a good choice for shell-only systems. Those files are read only by shells.
  4. /etc/<shell>.<shell>rc. Shell script. This is a poor choice because it is single shell specific.

另外,/etc/environment 不是脚本文件,而是由赋值表达式组成,每行一个.由于此文件存储系统范围的语言环境和路径设置,因此通常会引用该选项.不推荐使用/etc/profile .它仅存在于指向/etc/bash.bashrc 并从/etc/profile.d

Also, /etc/environment is not a script file, but rather consists of assignment expressions, one per line. Since this file stores the system-wide locale and path settings, it is most oft quoted choice. Using /etc/profile is not preferred. It exists only to point to /etc/bash.bashrc and to collect entries from /etc/profile.d

用户会话

  1. 〜/.pam_environment .唯一作业列表.在每个用户会话开始时由 PAM 加载(如果它是X,则无关紧要)窗口系统会话或外壳程序.您不能引用其他变量包括 HOME PATH ,因此使用范围有限.
  2. 〜/.xprofile Shell脚本.当用户登录到X Window System系统时,将执行此操作.此处定义的变量对每个X应用程序.用值扩展 PATH 的完美选择例如〜/bin 〜/go/bin 或定义用户特定的 GOPATH NPM_HOME .该文件包含在其他脚本中,因此请使用POSIX shell语法而不是用户外壳程序的语法.您的图形文本编辑器或通过快捷方式启动的IDE将看到这些值.
  3. 〜/.profile Shell脚本.仅对从终端或终端仿真器启动的程序可见.这是一个不错的选择仅限外壳的系统.
  4. 〜/.& lt; shell> rc .Shell脚本.这是一个糟糕的选择,因为它是特定于单个shell的.
  1. ~/.pam_environment. List of unique assignments. Loaded by PAM at the start of every user session irrelevant if it is an X Window System session or shell. You cannot reference other variable including HOME or PATH so it has limited use.
  2. ~/.xprofile Shell script. This is executed when the user logs into X Window System system. The variables defined here are visible to every X application. Perfect choice for extending PATH with values such as ~/bin or ~/go/bin or defining user specific GOPATH or NPM_HOME. The file is included by other script so use POSIX shell syntax not the syntax of your user shell. Your graphical text editor or IDE started by shortcut will see those values.
  3. ~/.profile Shell script. It will be visible only for programs started from terminal or terminal emulator. It is a good choice for shell-only systems.
  4. ~/.<shell>rc. Shell script. This is a poor choice because it is single shell specific.

这篇关于在Ubuntu中哪里设置了PATH变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆