Handbook:Parts/Working/USE/zh-cn

USE标志的指导思想
你在安装gentoo（或者是其他发行版，甚至于其他特定操作系统）的时候，你要依据你工作的环境做出选择. 服务器跟工作站的组织结构不同，游戏机跟3D工作站也会不一样.

不单只是选择你想要安装的包时如此，选择某一个包需要的特性时同样如此. 如果你不需要OpenGL，为什么还要花费时间安装OpenGL并在其他包中加入对OpenGL的支持？如果你不用KDE，而且软件包没有KDE也能完美运行，为什么还要在编译这些包的时候加入KDE支持？

为了帮用户判断什么需要安装或激活，什么不需要；我们希望用户能用简单的方式设定他们自己的环境. 这能促使用户判断他真正需要的东西，并让Portage做出有用的决定的过程变得简单.

USE标志的设定
我们来具体看看USE标志. 每一个标志都是代表对某特定概念的支持和依赖关系信息的关键字. 如果你设定了某个USE标志，Portage会明白你选择了支持这个选项. 当然这同时也改变了这个包的依赖关系信息.

让我们看一个特殊示例：关键字. 如果你的 USE 变量里面没有这个关键字，所有具有可选KDE支持的包在编译时都 不会 编译KDE支持. 所有具有可选KDE依赖关系的包在安装时都 不会 （做为一个依赖关系而）安装KDE库. 如果你设定了kde关键字，这些包在安装时都 会 编译KDE支持，而且KDE库也 会 （作为一个依赖关系而）被安装.

By correctly defining the keywords the system will be tailored specifically to the user's needs.

What USE flags exist
There are two types of USE flags: global and local USE flags.


 * A global USE flag is used by several packages, system-wide. This is what most people see as USE flags. A list of available global USE flags can be found on the main site or locally in the file.
 * A local USE flag is used by a single package to make package-specific decisions. A list of available local USE flags can be found on the main site or locally in the file.

Declare permanent USE flags
As previously mentioned, all USE flags are declared inside the USE variable. To make it easy for users to search and pick USE flags, we already provide a default USE setting. This setting is a collection of USE flags we think are commonly used by the Gentoo users. This default setting is declared in the files that are part of the selected profile.

The profile the system listens to is pointed to by the symlink. Each profile works on top of other profiles, and the end result is therefore the sum of all profiles. The top profile is the base profile.

To view the currently active USE flags (completely), use :

As can be seen, this variable already contains quite a lot of keywords. Do not alter any file to tailor the USE variable to personal needs though: changes in these file will be undone when the Gentoo repository is updated!

To change this default setting, add or remove keywords to/from the USE variable. This is done globally by defining the USE variable in. In this variable one can add the extra USE flags required, or remove the USE flags that are no longer needed. This latter is done by prefixing the keyword with the minus-sign.

For instance, to remove support for KDE and QT but add support for ldap, the following USE can be defined in :

Declaring USE flags for individual packages
Sometimes users want to declare a certain USE flag for one (or a couple) of applications but not system-wide. To accomplish this, edit. This is usually a single file, but can also be a directory; see for more information. The following examples assume is a single file.

For instance, to only have berkdb support for mysql:

Similarly it is possible to explicitly disable USE flags for a certain application. For instance, to disable java support in PHP (but have it for all other packages through the USE flag declaration in ):

Declaring temporary USE flags
Sometimes users need to set a USE flag for a brief moment. Instead of editing twice (to do and undo the USE changes) just declare the USE variable as an environment variable. Remember that this setting only applies for the command entered; re-emerging or updating this application (either explicitly or as part of a system update) will undo the changes that were triggered through the (temporary) USE flag definition.

The following example temporarily removes java from the USE setting during the installation of seamonkey:

Precedence
Of course there is a certain precedence on what setting has priority over the USE setting. The precedence for the USE setting is, ordered by priority (first has lowest priority):
 * 1) Default USE setting declared in the  files part of your profile
 * 2) User-defined USE setting in
 * 3) User-defined USE setting in
 * 4) User-defined USE setting as environment variable

To view the final USE setting as seen by Portage, run. This will list all relevant variables (including the USE variable) with their current definition as known to Portage.

Adapting the entire system to the new USE flags
After having altered USE flags, the system should be updated to reflect the necessary changes. To do so, use the  option with :

Next, run Portage's depclean to remove the conditional dependencies that were emerged on the "old" system but that have been obsoleted by the new USE flags.

When depclean has finished, run to rebuild the applications that are dynamically linked against shared objects provided by possibly removed packages. is part of the package; don't forget to emerge it first.

When all this is accomplished, the system is using the new USE flag settings.

Viewing available USE flags
Let's take the example of seamonkey: what USE flags does it listen to? To find out, we use with the   and   options:

isn't the only tool for this job. In fact, there is a tool dedicated to package information called which resides in the  package

Now run with the uses argument to view the USE flags of a certain package. For instance, for the gnumeric package:

Satisfying REQUIRED_USE conditions
Some ebuilds require or forbid certain combinations of USE flags in order to work properly. This is expressed via a set of conditions placed in a REQUIRED_USE expression. This conditions ensure that all features and dependencies are complete and that the build will succeed and perform as expected. If any of these are not met, emerge will alert you and ask you to fix the issue.

Some examples of this REQUIRED_USE  expression are given below: