According to the Filesystem Hierarchy Standard, /opt
is for "the installation of add-on application software packages". /usr/local
is "for use by the system administrator when installing software locally". These use cases seem pretty similar. Software not included with distributions usually is configured by default to install in either /usr/local
or /opt
with no particular rhyme or reason as to which they chose.
Is there some difference I'm missing, or do both do the same thing, but exist for historical reasons?
While both are designed to contain files not belonging to the operating system, /opt
and /usr/local
are not intended to contain the same set of files.
/usr/local
is a place to install files built by the administrator, typically by using the make
command (e.g., ./configure; make; make install
). The idea is to avoid clashes with files that are part of the operating system, which would either be overwritten or overwrite the local ones otherwise (e.g., /usr/bin/foo
is part of the OS while /usr/local/bin/foo
is a local alternative).
All files under /usr
are shareable between OS instances, although this is rarely done with Linux. This is a part where the FHS is slightly self-contradictory, as /usr
is defined to be read-only, but /usr/local/bin
needs to be read-write for local installation of software to succeed. The SVR4 file system standard, which was the FHS' main source of inspiration, is recommending to avoid /usr/local
and use /opt/local
instead to overcome this issue.
/usr/local
is a legacy from the original BSD. At that time, the source code of /usr/bin
OS commands were in /usr/src/bin
and /usr/src/usr.bin
, while the source of locally developed commands was in /usr/local/src
, and their binaries in /usr/local/bin
. There was no notion of packaging (outside tarballs).
另一方面,/opt
是一个目录,用于安装未捆绑的软件包(即,软件包不是操作系统发行版的一部分,但由独立的源提供),每个目录都位于其自己的子目录中。它们已经由独立的第三方软件发行商提供了完整的软件包。与/usr/local
包不同,这些包遵循目录约定(或至少应遵循)。例如,someapp
将安装在中/opt/someapp
,使用命令之一/opt/someapp/bin/foo
,将其配置文件安装在中/etc/opt/someapp/foo.conf
,并将日志文件安装在中/var/opt/someapp/logs/foo.access
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句