/[gentoo]/xml/htdocs/doc/en/handbook/hb-working-variables.xml
Gentoo

Contents of /xml/htdocs/doc/en/handbook/hb-working-variables.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download) (as text)
Wed Dec 17 17:05:59 2003 UTC (10 years, 9 months ago) by swift
Branch: MAIN
Changes since 1.3: +7 -1 lines
File MIME type: application/xml
Some minor changes

1 swift 1.1 <!-- The content of this document is licensed under the CC-BY-SA license -->
2     <!-- See http://creativecommons.org/licenses/by-sa/1.0 -->
3    
4 swift 1.4 <!-- $Header: /home/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-variables.xml,v 1.3 2003/12/16 18:37:29 swift Exp $ -->
5 swift 1.1
6     <sections>
7     <section>
8     <title>Environment Variables?</title>
9     <subsection>
10     <title>What they are</title>
11     <body>
12    
13 swift 1.2 <p>
14     An environment variable is a named object that contains information used by one
15     or more applications. Many users (and especially those new to Linux) find this a
16     bit weird or unmanageable. This is however wrong: by using environment variables
17     one can easily change a configuration setting for one or more applications.
18     </p>
19 swift 1.1
20     </body>
21     </subsection>
22     <subsection>
23     <title>Important Examples</title>
24     <body>
25    
26 swift 1.2 <p>
27     The following table lists a number of variables used by a Linux system and
28     describes their use. Example values are presented after the table.
29     </p>
30    
31     <table>
32     <tr>
33     <th>Variable</th>
34     <th>Description</th>
35     </tr>
36     <tr>
37     <ti>PATH</ti>
38     <ti>
39     This variable contains a colon-separated list of directories in which your
40     system looks for executable files. If you enter a name of an executable
41     (such as <c>ls</c>, <c>rc-update</c> or <c>emerge</c>) but this executable
42     is not located in a listed directory, your system will not execute it
43     (unless you enter the full path as command, such as <c>/bin/ls</c>).
44     </ti>
45     </tr>
46     <tr>
47     <ti>ROOTPATH</ti>
48     <ti>
49     This variable has the same function as <c>PATH</c>, but this one only lists
50     the directories that should be checked when the root-user enters a command.
51     </ti>
52     </tr>
53     <tr>
54     <ti>LDPATH</ti>
55     <ti>
56     This variable contains a colon-separated list of directories in which the
57     dynamical linker searches through to find a library.
58     </ti>
59     </tr>
60     <tr>
61     <ti>MANPATH</ti>
62     <ti>
63     This variable contains a colon-separated list of directories in which the
64     <c>man</c> command searches for the man pages.
65     </ti>
66     </tr>
67     <tr>
68     <ti>INFODIR</ti>
69     <ti>
70     This variable contains a colon-separated list of directories in which the
71     <c>info</c> command searches for the info pages.
72     </ti>
73     </tr>
74     <tr>
75     <ti>PAGER</ti>
76     <ti>
77     This variable contains the path to the program used to list the contents of
78     files through (such as <c>less</c> or <c>more</c>).
79     </ti>
80     </tr>
81     <tr>
82     <ti>EDITOR</ti>
83     <ti>
84     This variable contains the path to the program used to change the contents
85     of files with (such as <c>nano</c> or <c>vi</c>).
86     </ti>
87     </tr>
88     <tr>
89     <ti>KDEDIRS</ti>
90     <ti>
91     This variable contains a colon-separated list of directories which contain
92     KDE-specific material.
93     </ti>
94     </tr>
95     <tr>
96     <ti>CLASSPATH</ti>
97     <ti>
98     This variable contains a colon-separated list of directories which contain
99     Java classes.
100     </ti>
101     </tr>
102     <tr>
103     <ti>CONFIG_PROTECT</ti>
104     <ti>
105     This variable contains a <e>space</e>-delimited list of directories which
106     should be protected by Portage during updates.
107     </ti>
108     </tr>
109     <tr>
110     <ti>CONFIG_PROTECT_MASK</ti>
111     <ti>
112     This variable contains a <e>space</e>-delimited list of directories which
113     should not be protected by Portage during updates.
114     </ti>
115     </tr>
116     </table>
117    
118     <p>
119     Below you will find an example definition of all these variables:
120     </p>
121    
122     <pre caption="Example definitions">
123     PATH="/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/games/bin"
124     ROOTPATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
125     LDPATH="/lib:/usr/lib:/usr/local/lib:/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"
126     MANPATH="/usr/share/man:/usr/local/share/man"
127     INFODIR="/usr/share/info:/usr/local/share/info"
128     PAGER="/usr/bin/less"
129     EDITOR="/usr/bin/vim"
130 swift 1.4 KDEDIRS="/usr"
131     CLASSPATH="/opt/blackdown-jre-1.4.1/lib/rt.jar:."
132     CONFIG_PROTECT="/usr/X11R6/lib/X11/xkb /opt/tomcat/conf \
133     /usr/kde/3.1/share/config /usr/share/texmf/tex/generic/config/ \
134     /usr/share/texmf/tex/platex/config/ /usr/share/config"
135     CONFIG_PROTECT_MASK="/etc/gconf
136 swift 1.2 </pre>
137    
138 swift 1.1 </body>
139     </subsection>
140     </section>
141     <section>
142     <title>Defining Variables Globally</title>
143     <subsection>
144     <title>The /etc/env.d Directory</title>
145     <body>
146    
147 swift 1.2 <p>
148     To centralise the definitions of these variables, Gentoo introduced the
149     <path>/etc/env.d</path> directory. Inside this directory you will find a number
150     of files, such as <path>00basic</path>, <path>05gcc</path>, etc. which contain
151     the variables needed by the application mentioned in their name.
152     </p>
153    
154     <p>
155     For instance, when you installed <c>gcc</c>, a file called <path>05gcc</path>
156     was created by the ebuild which contains the definitions of the following
157     variables:
158     </p>
159    
160     <pre caption="/etc/conf.d/05gcc">
161     PATH="/usr/i686-pc-linux-gnu/gcc-bin/3.2"
162     ROOTPATH="/usr/i686-pc-linux-gnu/gcc-bin/3.2"
163     MANPATH="/usr/share/gcc-data/i686-pc-linux-gnu/3.2/man"
164     INFOPATH="/usr/share/gcc-data/i686-pc-linux-gnu/3.2/info"
165     CC="gcc"
166     CXX="g++"
167     LDPATH="/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3"
168     </pre>
169    
170     <p>
171     Other distributions tell you to change or add such environment variable
172     definitions in <path>/etc/profile</path> or other locations. Gentoo on the other
173     hand makes it easy for you (and for Portage) to maintain and manage the
174     environment variables without having to pay attention to the numerous files that
175     can contain environment variables.
176     </p>
177    
178     <p>
179     For instance, when <c>gcc</c> is updated, the <path>/etc/env.d/05gcc</path> file
180     is updated too without requesting any user-interaction.
181     </p>
182    
183     <p>
184     This doesn't only benefit Portage, but also you, as user. Occasionally you might
185     be asked to set a certain environment variable system-wide. As an example we
186     take the <c>http_proxy</c> variable. Instead of messing with
187     <path>/etc/profile</path>, you can now just create a file
188     (<path>/etc/env.d/99local</path>) and enter your definition(s) in it:
189     </p>
190    
191     <pre caption="/etc/env.d/99local">
192     http_proxy="proxy.server.com:8080"
193     </pre>
194    
195     <p>
196     By using the same file for all your variables, you have a quick overview on the
197     variables you have defined yourself.
198     </p>
199    
200 swift 1.1 </body>
201     </subsection>
202     <subsection>
203     <title>The env-update Script</title>
204     <body>
205    
206 swift 1.2 <p>
207     Several files in <path>/etc/env.d</path> define the <c>PATH</c> variable. This
208     is not wrong: when you run <c>env-update</c>, it will append the several
209     definitions before it updates the environment variables, thereby making it easy
210     for packages (or users) to add their own environment variable settings without
211     interfering with the already existing values.
212     </p>
213    
214     <p>
215     The <c>env-update</c> script will append the values in the alphabetical order of
216     the <path>/etc/env.d</path> files. This is why many of the files in
217     <path>/etc/env.d</path> begin with a number.
218     </p>
219    
220     <pre caption="Update order used by env-update">
221     00basic 99kde-env 99local
222     +-------------+----------------+-------------+
223     PATH="/bin:/usr/bin:/usr/kde/3.2/bin:/usr/local/bin"
224     </pre>
225    
226     <p>
227     When you run <c>env-update</c>, the script will create all environment variables
228     and place them in <path>/etc/profile.env</path> (which is used by
229     <path>/etc/profile</path>). It will also extract the information from the
230     <c>LDPATH</c> variable and use that to create <path>/etc/ld.so.conf</path>.
231     After this, it will run <c>ldconfig</c> to recreate the
232     <path>/etc/ld.so.cache</path> file used by the dynamical linker.
233     </p>
234    
235     <p>
236 swift 1.3 If you want to notice the effect of <c>env-update</c> immediately after you run
237     it, execute the following command to update your environment. Users who have
238 swift 1.2 installed Gentoo themselves will probably remember this from the installation
239     instructions:
240     </p>
241    
242     <pre caption="Updating the environment">
243     # <i>env-update &amp;&amp; source /etc/profile</i>
244     </pre>
245    
246 swift 1.1 </body>
247     </subsection>
248     </section>
249     <section>
250     <title>Defining Variables Locally</title>
251     <subsection>
252     <title>User Specific</title>
253     <body>
254    
255 swift 1.2 <p>
256     You do not always want to define an environment variable globally. For instance,
257     you might want to add <path>/home/my_user/bin</path> to the <c>PATH</c> variable
258     but don't want all other users on your system to have that in their <c>PATH</c>
259     too. If you want to define an environment variable locally, you should use
260     <path>~/.bashrc</path> or <path>~/.bash_profile</path>:
261     </p>
262    
263     <pre caption="Extending PATH for local usage in ~/.bashrc">
264     PATH="${PATH}:/home/my_user/bin"
265     </pre>
266    
267     <p>
268     When you relogin, your <c>PATH</c> variable will be updated.
269     </p>
270    
271 swift 1.1 </body>
272     </subsection>
273     <subsection>
274     <title>Session Specific</title>
275     <body>
276 swift 1.2
277     <p>
278     Sometimes even stricter definitions are requested. You might want to be able to
279     use binaries from a temporary directory you created without using the path to
280     the binaries themselves or editing <path>~/.bashrc</path> for those few moments
281     you need it.
282     </p>
283    
284     <p>
285     In this case, you can just define the <c>PATH</c> variable in your current
286     session by using the <c>export</c> command. As long as you don't log out, the
287     <c>PATH</c> variable will be using the temporary settings.
288     </p>
289    
290     <pre caption="Defining a session-specific environment variable">
291     # <i>export PATH="${PATH}:/home/my_user/tmp/usr/bin"</i>
292     </pre>
293 swift 1.1
294     </body>
295     </subsection>
296     </section>
297     </sections>

  ViewVC Help
Powered by ViewVC 1.1.20