Gentoo packages can build different optional features depending on the active USE flags, so the wrong scope can either leave a needed feature out or force unrelated packages to rebuild. A package-specific entry keeps the change tied to one package before Portage calculates the merge plan.
Portage combines USE values from several layers. The current shell environment has the highest precedence, package-specific entries under /etc/portage/package.use override system defaults, /etc/portage/make.conf supplies user-wide defaults, and the selected profile supplies the baseline flags.
Use /etc/portage/package.use when one package needs a feature such as ruby support in app-editors/vim. Use /etc/portage/make.conf only when the same flag should become a default for many packages, and preview the merge plan before rebuilding because a changed flag can add dependencies or require package rebuilds.
Related: How to edit Gentoo make.conf
Related: How to install a package on Gentoo with emerge
Related: How to update a Gentoo world set
Steps to set package-specific Gentoo USE flags:
- Preview the current package build plan.
$ emerge --pretend --verbose app-editors/vim [ebuild R ] app-editors/vim-9.1.1652-r2 USE="acl cscope gpm -ruby terminal vim-pager -perl" ##### snipped #####
The USE list shows enabled flags without a prefix and disabled flags with a leading -. Check the exact flags shown on your system before adding them to /etc/portage/package.use.
- Create the package-specific USE directory if it does not exist.
$ sudo install -d /etc/portage/package.use
- Open a package-specific file for the target package.
$ sudoedit /etc/portage/package.use/vim
The filename is for organization. Portage reads the entries inside /etc/portage/package.use and does not require the file to match the package name.
- Add the package atom and the flags to enable or disable.
app-editors/vim ruby
Prefix a flag with - to disable it for that package, such as app-editors/vim -ruby. Use one package atom per line with space-delimited flags.
- Confirm the saved package-specific entry.
$ cat /etc/portage/package.use/vim app-editors/vim ruby
- Preview the package again and confirm the intended flag changed.
$ emerge --pretend --verbose app-editors/vim [ebuild R ] app-editors/vim-9.1.1652-r2 USE="acl cscope gpm ruby terminal vim-pager -perl" ##### snipped #####
If emerge proposes unrelated changes, review the selected flag and dependencies before accepting the rebuild.
- Rebuild the package after the preview shows the intended USE state.
$ sudo emerge --ask --changed-use --oneshot app-editors/vim
–changed-use includes installed packages whose USE flags changed. –oneshot avoids adding a package to the world set when the rebuild is only needed to apply the flag change.
- Verify the installed package recorded the enabled flag.
$ cat /var/db/pkg/app-editors/vim-*/USE acl cscope gpm ruby terminal vim-pager
The /var/db/pkg record reflects the USE state saved when the package was merged. Re-run the emerge –pretend –verbose check if you also need to confirm that a disabled flag still appears with a leading - in the current build plan.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.