Handbuch:PPC/Arbeiten/Umgebungsvariablen

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Handbook:PPC/Working/EnvVar and the translation is 100% complete.
PPC Handbuch
Installation
Über die Installation
Auswahl des Mediums
Konfiguration des Netzwerks
Vorbereiten der Festplatte(n)
Installation des Stage Archivs
Installation des Basissystems
Konfiguration des Kernels
Konfiguration des Systems
Installation der Tools
Konfiguration des Bootloaders
Abschluss
Arbeiten mit Gentoo
Portage-Einführung
USE-Flags
Portage-Features
Initskript-System
Umgebungsvariablen
Arbeiten mit Portage
Dateien und Verzeichnisse
Variablen
Mischen von Softwarezweigen
Zusätzliche Tools
Eigener Portage-Tree
Erweiterte Portage-Features
Netzwerk-Konfiguration
Zu Beginn
Fortgeschrittene Konfiguration
Modulare Vernetzung
Drahtlose Netzwerke
Funktionalität hinzufügen
Dynamisches Management

Einleitung

Eine Umgebungsvariable ist ein benanntes Objekt, das Informationen enthält, die von einer oder mehreren Anwendungen verwendet werden. Durch die Verwendung von Umgebungsvariablen kann man auf einfache Weise eine Konfigurationseinstellung für eine oder mehrere Anwendungen ändern.

Wichtige Beispiele

Die folgende Tabelle enthält eine Reihe von Variablen, die von einem Linux-System verwendet werden, und beschreibt ihre Verwendung. Im Anschluss an die Tabelle sind Beispielwerte aufgeführt.

Variable Description
PATH This variable contains a colon-separated list of directories in which the system looks for executable files. If a name is entered of an executable (such as ls, rc-update, or emerge) but this executable is not located in a listed directory, then the system will not execute it (unless the full path is entered as the command, such as /bin/ls).
ROOTPATH This variable has the same function as PATH, but this one only lists the directories that should be checked when the root-user enters a command.
LDPATH This variable contains a colon-separated list of directories which the dynamic linker searches to find a library.
MANPATH This variable contains a colon-separated list of directories which the man(1) command searches for man pages.
INFODIR This variable contains a colon-separated list of directories which the info(1) command searches for info pages.
PAGER This variable contains the path to the program used to list the contents of files (such as less or more(1)).
EDITOR This variable contains the path to the program used to edit files (such as nano or vi).
KDEDIRS This variable contains a colon-separated list of directories which contain KDE-specific material.
CONFIG_PROTECT This variable contains a space-delimited list of directories which should be protected by Portage during package updates.
CONFIG_PROTECT_MASK This variable contains a space-delimited list of directories which should not be protected by Portage during package updates.

Nachstehend finden Sie ein Beispiel für die Definition all dieser Variablen:

CODE Example settings for the mentioned variables
PATH="/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/games/bin"
ROOTPATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
LDPATH="/lib:/usr/lib:/usr/local/lib:/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"
MANPATH="/usr/share/man:/usr/local/share/man"
INFODIR="/usr/share/info:/usr/local/share/info"
PAGER="/usr/bin/less"
EDITOR="/usr/bin/vim"
KDEDIRS="/usr"
# Directories that are protected during package updates.
# Note the use of the \ (backslashes) on the end of the following lines which interprets to a single space-delimited line.
CONFIG_PROTECT="/usr/X11R6/lib/X11/xkb /opt/tomcat/conf \
                /usr/kde/3.1/share/config /usr/share/texmf/tex/generic/config/ \
                /usr/share/texmf/tex/platex/config/ /usr/share/config"
# Directories that are _not_ protected during package updates.
CONFIG_PROTECT_MASK="/etc/gconf"

Globale Definition von Variablen

Das env.d-Verzeichnis

Um die Definition dieser Variablen zu zentralisieren, hat Gentoo das Verzeichnis /etc/env.d/ eingeführt. Innerhalb dieses Verzeichnisses gibt es eine Reihe von Dateien, wie z.B. 00basic, 05gcc, usw., die die Variablen enthalten, die von der im Namen genannten Anwendung benötigt werden.

Wenn z.B. gcc installiert wird, wurde eine Datei namens 05gcc vom Ebuild erstellt, die die Definition der folgenden Variablen enthält:

DATEI /etc/env.d/gcc/config-x86_64-pc-linux-gnuDefault gcc enabled environment variables for GCC 13
GCC_PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/13"
LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/13:/usr/lib/gcc/x86_64-pc-linux-gnu/13/32"
MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/13/man"
INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/13/info"
STDCXX_INCDIR="g++-v13"
CTARGET="x86_64-pc-linux-gnu"
GCC_SPECS=""
MULTIOSDIRS="../lib64:../lib"

Other distributions might tell the system administrator to change or add such environment variable definitions in /etc/profile or other locations. Gentoo on the other hand makes it easy for the sysadmins (and for Portage) to maintain and manage the environment variables without having to pay attention to the numerous files that can contain environment variables.

For instance, when gcc is updated, the associated file(s) under /etc/env.d/gcc are updated too without requesting any administrative interaction.

There are still occasions where a system administrator is asked to set a certain environment variable system-wide. As an example, take the http_proxy variable. Instead of editing a file under the /etc/profile directory, create a file named /etc/env.d/99local and enter the definition in it:

DATEI /etc/env.d/99localSetting a global environment variable
http_proxy="proxy.server.com:8080"

By using the same file for all customized environment variables, system administrators have a quick overview on the variables they have defined themselves.

env-update

Several files within the /etc/env.d directory add definitions to the PATH variable. This is not a mistake: when the env-update command is executed, it will append the several definitions before it atomically updates each environment variable, thereby making it easy for packages (or system administrators) to add their own environment variable settings without interfering with the already existing values.

The env-update script will append the values in the alphabetical order of the /etc/env.d/ files. The file names must begin with two decimal digits.

CODE Update order used by env-update
09sandbox    50baselayout     51dconf
     +------------+----------------+-----------+
CONFIG_PROTECT_MASK="/etc/sandbox.d /etc/gentoo-release /etc/dconf ..."

The concatenation of variables does not always happen, only with the following variables: ADA_INCLUDE_PATH, ADA_OBJECTS_PATH, CLASSPATH, KDEDIRS, PATH, LDPATH, MANPATH, INFODIR, INFOPATH, ROOTPATH, CONFIG_PROTECT, CONFIG_PROTECT_MASK, PRELINK_PATH, PRELINK_PATH_MASK, PKG_CONFIG_PATH, and PYTHONPATH. For all other variables the latest defined value (in alphabetical order of the files in /etc/env.d/) is used.

It is possible to add more variables into this list of concatenate-variables by adding the variable name to either COLON_SEPARATED or SPACE_SEPARATED variables (also inside an /etc/env.d/ file).

When executing env-update, the script will create all environment variables and place them in /etc/profile.env (which is used by /etc/profile). It will also extract the information from the LDPATH variable and use that to create /etc/ld.so.conf. After this, it will run ldconfig to recreate the /etc/ld.so.cache file used by the dynamical linker.

To notice the effect of env-update immediately after running it, execute the following command to update the environment. Users who have installed Gentoo themselves will probably remember this from the installation instructions:

root #env-update && source /etc/profile
Hinweis
The above command only updates the variables in the current terminal, new consoles, and their children. Thus, if the user is working in X11, he needs to either type source /etc/profile in every new terminal opened or restart X so that all new terminals source the new variables. If a login manager is used, it is necessary to become root and restart the /etc/init.d/xdm service.
Wichtig
It is not possible to use shell variables when defining other variables. This means things like FOO="$BAR" (where $BAR is another variable) are forbidden.

Defining variables locally

User specific

It might not be necessary to define an environment variable globally. For instance, one might want to add /home/my_user/bin and the current working directory (the directory the user is in) to the PATH variable but not want all other users on the system to have those directories in their PATH. To define an environment variable locally, use ~/.bashrc (for all interactive shell sessions) or ~/.bash_profile (for login shell sessions):

DATEI ~/.bashrcExtending PATH for local usage
# A colon followed by no directory is treated as the current working directory
PATH="${PATH}:/home/my_user/bin:"

After logout/login, the PATH variable will be updated.

Session specific

Sometimes even stricter definitions are required. For instance, a user might want to be able to use binaries from a temporary directory without needing to use the full path to the binaries and without needing to temporarily change ~/.bashrc.

In this case, just define the PATH variable in the current session by using the export command. As long as the user does not log out, the PATH variable will be using the temporary settings.

root #export PATH="${PATH}:/home/my_user/tmp/usr/bin"