mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-13 22:30:37 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
29196682da
@ -1,19 +1,18 @@
|
||||
|
||||
如何在Linux/Unix中的Web服务根文档目录(DocumentRoot)上设置只读文件权限
|
||||
如何在 Web 服务器文档根目录上设置只读文件权限
|
||||
======
|
||||
我是如何对存放在/var/www/html/目录中的所有我的文件设置只读权限的?
|
||||
|
||||
**Q:如何对我存放在 `/var/www/html/` 目录中的所有文件设置只读权限?**
|
||||
|
||||
你可以使用 `chmod` 命令对 Linux/Unix/macOS/OS X/*BSD 操作系统上的所有文件来设置只读权限。这篇文章介绍如何在 Linux/Unix 的 web 服务器(如 Nginx、 Lighttpd、 Apache 等)上来设置只读文件权限。
|
||||
|
||||
你可以使用`chmod`命令对Linux / Unix / macOS / Apple OS X / *BSD操作系统上的所有文件来设置只读权限。这篇文章介绍如何在Linux/Unix的web服务器(如 Nginx, Lighttpd, Apache等)上来设置只读文件权限。
|
||||
[![Proper read-only permissions for Linux/Unix Nginx/Apache web server's directory][1]][1]
|
||||
|
||||
### 如何设置文件为只读模式
|
||||
|
||||
|
||||
语法为:
|
||||
|
||||
```
|
||||
### 仅针对文件 ##
|
||||
### 仅针对文件 ###
|
||||
chmod 0444 /var/www/html/*
|
||||
chmod 0444 /var/www/html/*.php
|
||||
```
|
||||
@ -21,54 +20,59 @@ chmod 0444 /var/www/html/*.php
|
||||
### 如何设置目录为只读模式
|
||||
|
||||
语法为:
|
||||
|
||||
```
|
||||
### 仅针对目录##
|
||||
### 仅针对目录 ###
|
||||
chmod 0444 /var/www/html/
|
||||
chmod 0444 /path/to/your/dir/
|
||||
# ***************************************************************************
|
||||
# Say webserver user/group is www-data, and file-owned by ftp-data user/group
|
||||
# 假如webserver用户/用户组是www-data ,文件拥有者是ftp-data用户/用户组
|
||||
# 假如 web 服务器的用户/用户组是 www-data,文件拥有者是 ftp-data 用户/用户组
|
||||
# ***************************************************************************
|
||||
# 设置目录所有文件为只读
|
||||
chmod -R 0444 /var/www/html/
|
||||
#设置文件/目录拥有者为ftp-data
|
||||
# 设置文件/目录拥有者为 ftp-data
|
||||
chown -R ftp-data:ftp-data /var/www/html/
|
||||
# 所有目录和子目录的权限为0445 (这样webserver用户或用户组就可以读取我们的文件)
|
||||
# 所有目录和子目录的权限为 0445 (这样 web 服务器的用户或用户组就可以读取我们的文件)
|
||||
find /var/www/html/ -type d -print0 | xargs -0 -I {} chmod 0445 "{}"
|
||||
```
|
||||
找到所有/var/www/html下的所有文件(包括子目录),键入:
|
||||
|
||||
找到所有 `/var/www/html` 下的所有文件(包括子目录),键入:
|
||||
|
||||
```
|
||||
### 仅对文件有效##
|
||||
### 仅对文件有效 ###
|
||||
find /var/www/html -type f -iname "*" -print0 | xargs -I {} -0 chmod 0444 {}
|
||||
```
|
||||
然而,你需要在/var/www/html目录及其子目录上设置只读和执行权限,如此才能让web server能够访问根目录,键入:
|
||||
|
||||
然而,你需要在 `/var/www/html` 目录及其子目录上设置只读和执行权限,如此才能让 web 服务器能够访问根目录,键入:
|
||||
|
||||
```
|
||||
### 仅对目录有效 ##
|
||||
### 仅对目录有效 ###
|
||||
find /var/www/html -type d -iname "*" -print0 | xargs -I {} -0 chmod 0544 {}
|
||||
```
|
||||
|
||||
### 警惕写权限
|
||||
|
||||
请注意在 `/var/www/html/` 目录上的写权限会允许任何人删除文件或添加新文件。也就是说,你可能需要设置一个只读权限给 `/var/www/html/` 目录本身。
|
||||
|
||||
请注意在/var/www/html/目录上的写权限会允许任何人删除文件或添加新文件。也就是说,你可能需要设置一个只读权限给/var/www/html/目录本身。
|
||||
```
|
||||
### web根目录只读##
|
||||
### web根目录只读 ###
|
||||
chmod 0555 /var/www/html
|
||||
```
|
||||
|
||||
在某些情况下,根据你的设置要求,你可以改变文件的属主和属组来设置严格的权限。
|
||||
|
||||
```
|
||||
### 如果/var/www/html目录的拥有人是普通用户,你可以设置拥有人为: root:root 或 httpd:httpd (推荐) ###
|
||||
### 如果 /var/www/html 目录的拥有人是普通用户,你可以设置拥有人为:root:root 或 httpd:httpd (推荐) ###
|
||||
chown -R root:root /var/www/html/
|
||||
|
||||
### 确保apache拥有/var/www/html/ ##
|
||||
### 确保 apache 拥有 /var/www/html/ ###
|
||||
chown -R apache:apache /var/www/html/
|
||||
```
|
||||
|
||||
### 关于NFS导出目录
|
||||
### 关于 NFS 导出目录
|
||||
|
||||
你可以在 `/etc/exports` 文件中指定哪个目录应该拥有[只读或者读写权限 ][2]。这个文件定义各种各样的共享在 NFS 服务器和他们的权限。如:
|
||||
|
||||
你可以在/etc/exports文件中指定哪个目录应该拥有[只读或者读写权限 ][2] . 这个文件定义各种各样的共享在NFS服务器和他们的权限。如:
|
||||
|
||||
```
|
||||
# 对任何人只读权限
|
||||
@ -78,11 +82,11 @@ chown -R apache:apache /var/www/html/
|
||||
/var/www/html 192.168.1.10(rw,sync)
|
||||
```
|
||||
|
||||
|
||||
### 关于Samba (CIFS)只读共享对MS-Windows客户端
|
||||
### 关于用于 MS-Windows客户端的 Samba(CIFS)只读共享
|
||||
|
||||
|
||||
共享sales为只读,更新smb.conf,如下:
|
||||
要以只读共享 `sales`,更新 `smb.conf`,如下:
|
||||
|
||||
```
|
||||
[sales]
|
||||
comment = Sales Data
|
||||
@ -91,39 +95,47 @@ read only = Yes
|
||||
guest ok = Yes
|
||||
```
|
||||
|
||||
### 关于文件系统表(file systems table)
|
||||
### 关于文件系统表(fstab)
|
||||
|
||||
你可以在 Unix/Linux 上的 `/etc/fstab` 文件中配置挂载某些文件为只读模式。
|
||||
|
||||
你可以在Unix/Linux上的/etc/fstab文件中配置挂载某些文件为只读模式。
|
||||
你需要有专用分区,不要设置其他系统分区为只读模式。
|
||||
|
||||
如下在/etc/fstab文件中设置/srv/html为只读模式。
|
||||
如下在 `/etc/fstab` 文件中设置 `/srv/html` 为只读模式。
|
||||
|
||||
```
|
||||
/dev/sda6 /srv/html ext4 ro 1 1
|
||||
```
|
||||
你可以使用`mount`命令[重新挂载分区为只读模式][3](使用root用户)
|
||||
|
||||
你可以使用 `mount` 命令[重新挂载分区为只读模式][3](使用 root 用户)
|
||||
|
||||
```
|
||||
# mount -o remount,ro /dev/sda6 /srv/html
|
||||
```
|
||||
|
||||
或者
|
||||
|
||||
```
|
||||
# mount -o remount,ro /srv/html
|
||||
```
|
||||
|
||||
上面的命令会尝试重新挂载已挂载的文件系统到 `/srv/html`上。这是改变文件系统挂载标志的常用方法,特别是让只读文件改为可写的。这种方式不会改变设备或者挂载点。让文件变得再次可写,键入:
|
||||
|
||||
上面的命令会尝试重新挂载已挂载的文件系统在/srv/html上。这是改变文件系统挂载标志的常用方法,特别是让只读文件改为可写的。这种方式不会改变设备或者挂载点。让文件变得再次可写,键入:
|
||||
```
|
||||
# mount -o remount,rw /dev/sda6 /srv/html
|
||||
```
|
||||
|
||||
或
|
||||
|
||||
```
|
||||
# mount -o remount,rw /srv/html
|
||||
```
|
||||
|
||||
### Linux: chattr 命令
|
||||
### Linux:chattr 命令
|
||||
|
||||
|
||||
你可以在Linux文件系统上使用`chattr`命令[改变文件属性为只读][4],如:
|
||||
你可以在 Linux 文件系统上使用 `chattr` 命令[改变文件属性为只读][4],如:
|
||||
|
||||
```
|
||||
chattr +i /path/to/file.php
|
||||
chattr +i /var/www/html/
|
||||
@ -132,13 +144,13 @@ chattr +i /var/www/html/
|
||||
find /var/www/html -iname "*" -print0 | xargs -I {} -0 chattr +i {}
|
||||
```
|
||||
|
||||
通过提供 `-i` 选项可删除只读属性:
|
||||
|
||||
通过提供`-i`选项可删除只读属性
|
||||
```
|
||||
chattr -i /path/to/file.php
|
||||
```
|
||||
|
||||
FreeBSD, Mac OS X 和其他BSD Unix用户可使用[`chflags`命令][5]:
|
||||
FreeBSD、Mac OS X 和其他 BSD Unix 用户可使用[`chflags`命令][5]:
|
||||
|
||||
```
|
||||
### 设置只读 ##
|
||||
@ -148,14 +160,13 @@ chflags schg /path/to/file.php
|
||||
chflags noschg /path/to/file.php
|
||||
```
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
来源: https://www.cyberciti.biz/faq/howto-set-readonly-file-permission-in-linux-unix/
|
||||
via: https://www.cyberciti.biz/faq/howto-set-readonly-file-permission-in-linux-unix/
|
||||
|
||||
作者:[Vivek Gite][a]
|
||||
译者:[yizhuoyan](https://github.com/yizhuoyan)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,11 +1,13 @@
|
||||
使用树莓派和 pi-hole 拦截你的网络上的广告
|
||||
在你的网络中使用树莓派和 Pi-hole 拦截广告
|
||||
======
|
||||
|
||||
> 痛恨上网时看到广告?学习这篇教程来设置 Pi-hole。
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/pi-hole-banner.png?itok=1TXcp3hm)
|
||||
|
||||
有一个闲置的树莓派?在浏览网页时讨厌广告?[Pi-hole][1] 是一个拦截广告的开源软件项目,它可以将你的家庭网络上的所有广告路由到一个不存在的地方,从而实现在你的设备上拦截广告的目的。这么好的方法只需要花几钟的时间来设置,你就可以使用它了。
|
||||
|
||||
Pi-hole 拦截了超过 100,000 个提供广告的域名,它可以拦截任何设备(包括移动设备、平板电脑、以及个人电脑)上的广告,并且它是完整的拦截了广告,而不是仅将它们隐藏起来,它这样做可以提升总体的网络性能(因为广告不需要下载)。你可以在一个 web 界面上、或者也可以使用一个 API 来监视性能和统计数据。
|
||||
Pi-hole 拦截了超过 100,000 个提供广告的域名,它可以拦截任何设备(包括移动设备、平板电脑、以及个人电脑)上的广告,并且它是完整的拦截了广告,而不是仅将它们隐藏起来,这样做可以提升总体的网络性能(因为广告不需要下载)。你可以在一个 web 界面上、或者也可以使用一个 API 来监视性能和统计数据。
|
||||
|
||||
### 你需要:
|
||||
|
||||
@ -19,7 +21,7 @@ Pi-hole 拦截了超过 100,000 个提供广告的域名,它可以拦截任何
|
||||
![](https://opensource.com/sites/default/files/u128651/power-supply.png)
|
||||
![](https://opensource.com/sites/default/files/u128651/ethernet-cable.png)
|
||||
|
||||
你不需要使用一个最新型号的树莓派 — 一个老款足够完成这项工作,只要它的内存不小于 512MB 就可以 — 因此一个一代树莓派 Model B(rev 2)就足够,一个 Model B+、或者二代的或者三代的树莓派都可以。你可能需要一个 Pi Zero,也需要一个 USB micro 以太网适配器。你可以使用一个带 WiFi 的 Pi Zero W 而不是以太网。但是,作为你的网络基础设施的一部分,我建议你使用一个性能良好、稳定的有线连接来代替 WiFi 连接。
|
||||
你不需要使用一个最新型号的树莓派 — 一个老款足够完成这项工作,只要它的内存不小于 512MB 就可以 — 因此一个一代树莓派 Model B(rev 2)就足够,一个 Model B+、或者二代的或者三代的树莓派都可以。你可以使用 Pi Zero,但需要一个 USB micro 以太网适配器。你可以使用一个带 WiFi 的 Pi Zero W 而不是以太网。但是,作为你的网络基础设施的一部分,我建议你使用一个性能良好、稳定的有线连接来代替 WiFi 连接。
|
||||
|
||||
### 准备 SD 卡
|
||||
|
||||
@ -33,14 +35,14 @@ Pi-hole 拦截了超过 100,000 个提供广告的域名,它可以拦截任何
|
||||
|
||||
![](https://opensource.com/sites/default/files/etcher-win-520px.png)
|
||||
|
||||
SD 卡准备完成之后,你可以将它插入到你的树莓派,连接上键盘、显示器、和以太网,然后为树莓派接上电源。在初始化设置之后,这个树莓派就不需要键盘或显示器了。如果你有使用”无头“树莓派工作的经验,你可以去 [启用 SSH][4] 然后去设置它 [启用远程连接][5]。
|
||||
SD 卡准备完成之后,你可以将它插入到你的树莓派,连接上键盘、显示器和以太网,然后为树莓派接上电源。在初始化设置之后,这个树莓派就不需要键盘或显示器了。如果你有使用“<ruby>无末端<rt>headless</rt></ruby>”树莓派工作的经验,你可以 [启用 SSH][4] 然后去设置它 [启用远程连接][5]。
|
||||
|
||||
### 安装 Pi-hole
|
||||
|
||||
在你的树莓派引导完成之后,用缺省用户名(`pi`)和密码(`raspberry`)登入。现在你就可以运行命令行了,可以去安装 Pi-hole 了。简单地输入下列命令并回车:
|
||||
|
||||
```
|
||||
curl -sSL https://install.pi-hole.net | bash
|
||||
|
||||
```
|
||||
|
||||
这个命令下载了 Pi-hole 安装脚本然后去运行它。你可以在你的电脑浏览器中输入 `https://install.pi-hole.net` 来查看它的内容,你将会看到这个脚本做了些什么。它为你生成了一个**管理员密码**,并和其它安装信息一起显示在你的屏幕上。
|
||||
@ -59,17 +61,17 @@ curl -sSL https://install.pi-hole.net | bash
|
||||
|
||||
关于这一步的更多信息,可以查看 [Pi-hole discourse][6]。
|
||||
|
||||
你还需要确保你的 Pi-hole 始终保持相同的 IP 地址,因此,你需要去查看 DHCP,将你的树莓派的 IP 地址条目添加到保留地址中。
|
||||
你还需要确保你的 Pi-hole 始终保持相同的 IP 地址,因此,你需要去查看 DHCP 设置,将你的树莓派的 IP 地址条目添加到保留地址中。
|
||||
|
||||
### 外部测试
|
||||
|
||||
现在,在命令行下输入 `sudo halt` 关闭运行的树莓派,并断开它的电源。你可以拔掉显示器连接线和键盘,然后将你的树莓派放置到一个合适的固定的地方 — 或许应该将它放在你的路由器附近。确保连接着以太网线,然后重新连接电源以启动它。
|
||||
|
||||
在你的个人电脑上导航到一个网站(强烈建议访问 [Opensource.com][7] 网站),或者用你的 WiFi 中的一个设备去检查你的因特网访问是否正常(如果不能正常访问,可能是你的 DNS 配置错误)。如果在浏览器中看到了预期的结果,说明它的工作正常。现在,你浏览网站时,应该再也看不到广告了!甚至在你的 apps 中提供的广告也无法出现在你的移动设备中!祝你”冲浪“愉快!
|
||||
在你的个人电脑上导航到一个网站(强烈建议访问 [Opensource.com][7] 网站),或者用你的 WiFi 中的一个设备去检查你的因特网访问是否正常(如果不能正常访问,可能是你的 DNS 配置错误)。如果在浏览器中看到了预期的结果,说明它的工作正常。现在,你浏览网站时,应该再也看不到广告了!甚至在你的 app 中提供的广告也无法出现在你的移动设备中!祝你“冲浪”愉快!
|
||||
|
||||
如果你想去测试一下你的广告拦截的新功能,你可以去这个 [测试页面][8] 尝试浏览一些内置广告的网站。
|
||||
|
||||
现在你可以在你的电脑浏览器上输入 Pi-hole 的 IP 地址来访问它的 web 界面(比如,<http://192.168.1.4/admin> \- 或者 `http://pi.hole/admin` 也可能会工作)。你将看到 Pi-hole 管理面板和一些统计数据(在这时可能数字比较小)。在你输入密码(在安装时显示在屏幕上的)后,你将看到更漂亮的图形界面:
|
||||
现在你可以在你的电脑浏览器上输入 Pi-hole 的 IP 地址来访问它的 web 界面(比如,`http://192.168.1.4/admin` 或者 `http://pi.hole/admin` 也可能会工作)。你将看到 Pi-hole 管理面板和一些统计数据(在这时可能数字比较小)。在你输入(在安装时显示在屏幕上的)密码后,你将看到更漂亮的图形界面:
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/pi-hole-web.png)
|
||||
|
||||
@ -87,7 +89,7 @@ via: https://opensource.com/article/18/2/block-ads-raspberry-pi
|
||||
|
||||
作者:[Ben Nuttall][a]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,263 +0,0 @@
|
||||
Translating By MjSeven
|
||||
|
||||
How to install software applications on Linux
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux-penguins.png?itok=yKOpaJM_)
|
||||
|
||||
Image by : Internet Archive Book Images. Modified by Opensource.com. CC BY-SA 4.0
|
||||
|
||||
How do you install an application on Linux? As with many operating systems, there isn't just one answer to that question. Applications can come from so many sources--it's nearly impossible to count--and each development team may deliver their software whatever way they feel is best. Knowing how to install what you're given is part of being a true power user of your OS.
|
||||
|
||||
### Repositories
|
||||
|
||||
For well over a decade, Linux has used software repositories to distribute software. A "repository" in this context is a public server hosting installable software packages. A Linux distribution provides a command, and usually a graphical interface to that command, that pulls the software from the server and installs it onto your computer. It's such a simple concept that it has served as the model for all major cellphone operating systems and, more recently, the "app stores" of the two major closed source computer operating systems.
|
||||
|
||||
|
||||
![Linux repository][2]
|
||||
|
||||
Not an app store
|
||||
|
||||
Installing from a software repository is the primary method of installing apps on Linux. It should be the first place you look for any application you intend to install.
|
||||
|
||||
To install from a software repository, there's usually a command:
|
||||
```
|
||||
|
||||
|
||||
$ sudo dnf install inkscape
|
||||
```
|
||||
|
||||
The actual command you use depends on what distribution of Linux you use. Fedora uses `dnf`, OpenSUSE uses `zypper`, Debian and Ubuntu use `apt`, Slackware uses `sbopkg`, FreeBSD uses `pkg_add`, and Illumos-based OpenIndiana uses `pkg`. Whatever you use, the incantation usually involves searching for the proper name of what you want to install, because sometimes what you call software is not its official or solitary designation:
|
||||
```
|
||||
|
||||
|
||||
$ sudo dnf search pyqt
|
||||
|
||||
PyQt.x86_64 : Python bindings for Qt3
|
||||
|
||||
PyQt4.x86_64 : Python bindings for Qt4
|
||||
|
||||
python-qt5.x86_64 : PyQt5 is Python bindings for Qt5
|
||||
```
|
||||
|
||||
Once you have located the name of the package you want to install, use the `install` subcommand to perform the actual download and automated install:
|
||||
```
|
||||
|
||||
|
||||
$ sudo dnf install python-qt5
|
||||
```
|
||||
|
||||
For specifics on installing from a software repository, see your distribution's documentation.
|
||||
|
||||
The same generally holds true with the graphical tools. Search for what you think you want, and then install it.
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/apper.png)
|
||||
|
||||
Like the underlying command, the name of the graphical installer depends on what distribution you are running. The relevant application is usually tagged with the software or package keywords, so search your launcher or menu for those terms, and you'll find what you need. Since open source is all about user choice, if you don't like the graphical user interface (GUI) that your distribution provides, there may be an alternative that you can install. And now you know how to do that.
|
||||
|
||||
#### Extra repositories
|
||||
|
||||
Your distribution has its standard repository for software that it packages for you, and there are usually extra repositories common to your distribution. For example, [EPEL][3] serves Red Hat Enterprise Linux and CentOS, [RPMFusion][4] serves Fedora, Ubuntu has various levels of support as well as a Personal Package Archive (PPA) network, [Packman][5] provides extra software for OpenSUSE, and [SlackBuilds.org][6] provides community build scripts for Slackware.
|
||||
|
||||
By default, your Linux OS is set to look at just its official repositories, so if you want to use additional software collections, you must add extra repositories yourself. You can usually install a repository as though it were a software package. In fact, when you install certain software, such as [GNU Ring][7] video chat, the [Vivaldi][8] web browser, Google Chrome, and many others, what you are actually installing is access to their private repositories, from which the latest version of their application is installed to your machine.
|
||||
|
||||
|
||||
![Installing a repo][10]
|
||||
|
||||
Installing a repo
|
||||
|
||||
You can also add the repository manually by editing a text file and adding it to your package manager's configuration directory, or by running a command to install the repository. As usual, the exact command you use depends on the distribution you are running; for example, here is a `dnf` command that adds a repository to the system:
|
||||
```
|
||||
|
||||
|
||||
$ sudo dnf config-manager --add-repo=http://example.com/pub/centos/7
|
||||
```
|
||||
|
||||
### Installing apps without repositories
|
||||
|
||||
The repository model is so popular because it provides a link between the user (you) and the developer. When important updates are released, your system kindly prompts you to accept the updates, and you can accept them all from one centralized location.
|
||||
|
||||
Sometimes, though, there are times when a package is made available with no repository attached. These installable packages come in several forms.
|
||||
|
||||
#### Linux packages
|
||||
|
||||
Sometimes, a developer distributes software in a common Linux packaging format, such as RPM, DEB, or the newer but very popular FlatPak or Snap formats. You make not get access to a repository with this download; you might just get the package.
|
||||
|
||||
The video editor [Lightworks][11], for example, provides a `.deb` file for APT users and an `.rpm` file for RPM users. When you want to update, you return to the website and download the latest appropriate file.
|
||||
|
||||
These one-off packages can be installed with all the same tools used when installing from a repository. If you double-click the package you download, a graphical installer launches and steps you through the install process.
|
||||
|
||||
Alternately, you can install from a terminal. The difference here is that a lone package file you've downloaded from the internet isn't coming from a repository. It's a "local" install, meaning your package management software doesn't need to download it to install it. Most package managers handle this transparently:
|
||||
```
|
||||
|
||||
|
||||
$ sudo dnf install ~/Downloads/lwks-14.0.0-amd64.rpm
|
||||
```
|
||||
|
||||
In some cases, you need to take additional steps to get the application to run, so carefully read the documentation about the software you're installing.
|
||||
|
||||
#### Generic install scripts
|
||||
|
||||
Some developers release their packages in one of several generic formats. Common extensions include `.run` and `.sh`. NVIDIA graphic card drivers, Foundry visual FX packages like Nuke and Mari, and many DRM-free games from [GOG][12] use this style of installer.
|
||||
|
||||
This model of installation relies on the developer to deliver an installation "wizard." Some of the installers are graphical, while others just run in a terminal.
|
||||
|
||||
There are two ways to run these types of installers.
|
||||
|
||||
1. You can run the installer directly from a terminal:
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
$ sh ./game/gog_warsow_x.y.z.sh
|
||||
```
|
||||
|
||||
2. Alternately, you can run it from your desktop by marking it as executable. To mark an installer executable, right-click on its icon and select **Properties**.
|
||||
|
||||
![Giving an installer executable permission][14]
|
||||
|
||||
|
||||
Giving an installer executable permission
|
||||
|
||||
Once you've given permission for it to run, double-click the icon to start the install.
|
||||
|
||||
![GOG installer][16]
|
||||
|
||||
GOG installer
|
||||
|
||||
For the rest of the install, just follow the instructions on the screen.
|
||||
|
||||
#### AppImage portable apps
|
||||
|
||||
The AppImage format is relatively new to Linux, although its concept is based on both NeXT and Rox. The idea is simple: everything required to run an application is placed into one directory, and then that directory is treated as an "app." To run the application, you just double-click the icon, and it runs. There's no need or expectation that the application is installed in the traditional sense; it just runs from wherever you have it lying around on your hard drive.
|
||||
|
||||
Despite its ability to run as a self-contained app, an AppImage usually offers to do some soft system integration.
|
||||
|
||||
![AppImage system integration][18]
|
||||
|
||||
AppImage system integration
|
||||
|
||||
If you accept this offer, a local `.desktop` file is installed to your home directory. A `.desktop` file is a small configuration file used by the Applications menu and mimetype system of a Linux desktop. Essentially, placing the desktop config file in your home directory's application list "installs" the application without actually installing it. You get all the benefits of having installed something, and the benefits of being able to run something locally, as a "portable app."
|
||||
|
||||
#### Application directory
|
||||
|
||||
Sometimes, a developer just compiles an application and posts the result as a download, with no install script and no packaging. Usually, this means that you download a TAR file, [extract it][19], and then double-click the executable file (it's usually the one with the name of the software you downloaded).
|
||||
|
||||
![Twine downloaded for Linux][21]
|
||||
|
||||
|
||||
Twine downloaded for Linux
|
||||
|
||||
When presented with this style of software delivery, you can either leave it where you downloaded it and launch it manually when you need it, or you can do a quick and dirty install yourself. This involves two simple steps:
|
||||
|
||||
1. Save the directory to a standard location and launch it manually when you need it.
|
||||
2. Save the directory to a standard location and create a `.desktop` file to integrate it into your system.
|
||||
|
||||
|
||||
|
||||
If you're just installing applications for yourself, it's traditional to keep a `bin` directory (short for "binary") in your home directory as a storage location for locally installed applications and scripts. If you have other users on your system who need access to the applications, it's traditional to place the binaries in `/opt`. Ultimately, it's up to you where you store the application.
|
||||
|
||||
Downloads often come in directories with versioned names, such as `twine_2.13` or `pcgen-v6.07.04`. Since it's reasonable to assume you'll update the application at some point, it's a good idea to either remove the version number or to create a symlink to the directory. This way, the launcher that you create for the application can remain the same, even though you update the application itself.
|
||||
|
||||
To create a `.desktop` launcher file, open a text editor and create a file called `twine.desktop`. The [Desktop Entry Specification][22] is defined by [FreeDesktop.org][23]. Here is a simple launcher for a game development IDE called Twine, installed to the system-wide `/opt` directory:
|
||||
```
|
||||
|
||||
|
||||
[Desktop Entry]
|
||||
|
||||
Encoding=UTF-8
|
||||
|
||||
Name=Twine
|
||||
|
||||
GenericName=Twine
|
||||
|
||||
Comment=Twine
|
||||
|
||||
Exec=/opt/twine/Twine
|
||||
|
||||
Icon=/usr/share/icons/oxygen/64x64/categories/applications-games.png
|
||||
|
||||
Terminal=false
|
||||
|
||||
Type=Application
|
||||
|
||||
Categories=Development;IDE;
|
||||
```
|
||||
|
||||
The tricky line is the `Exec` line. It must contain a valid command to start the application. Usually, it's just the full path to the thing you downloaded, but in some cases, it's something more complex. For example, a Java application might need to be launched as an argument to Java itself:
|
||||
```
|
||||
|
||||
|
||||
Exec=java -jar /path/to/foo.jar
|
||||
```
|
||||
|
||||
Sometimes, a project includes a wrapper script that you can run so you don't have to figure out the right command:
|
||||
```
|
||||
|
||||
|
||||
Exec=/opt/foo/foo-launcher.sh
|
||||
```
|
||||
|
||||
In the Twine example, there's no icon bundled with the download, so the example `.desktop` file assigns a generic gaming icon that shipped with the KDE desktop. You can use workarounds like that, but if you're more artistic, you can just create your own icon, or you can search the Internet for a good icon. As long as the `Icon` line points to a valid PNG or SVG file, your application will inherit the icon.
|
||||
|
||||
The example script also sets the application category primarily to Development, so in KDE, GNOME, and most other Application menus, Twine appears under the Development category.
|
||||
|
||||
To get this example to appear in an Application menu, place the `twine.desktop` file into one of two places:
|
||||
|
||||
* Place it in `~/.local/share/applications` if you're storing the application in your own home directory.
|
||||
* Place it in `/usr/share/applications` if you're storing the application in `/opt` or another system-wide location and want it to appear in all your users' Application menus.
|
||||
|
||||
|
||||
|
||||
And now the application is installed as it needs to be and integrated with the rest of your system.
|
||||
|
||||
### Compiling from source
|
||||
|
||||
Finally, there's the truly universal install format: source code. Compiling an application from source code is a great way to learn how applications are structured, how they interact with your system, and how they can be customized. It's by no means a push-button process, though. It requires a build environment, it usually involves installing dependency libraries and header files, and sometimes a little bit of debugging.
|
||||
|
||||
To learn more about compiling from source code, [read my article][24] on the topic.
|
||||
|
||||
### Now you know
|
||||
|
||||
Some people think installing software is a magical process that only developers understand, or they think it "activates" an application, as if the binary executable file isn't valid until it has been "installed." Hopefully, learning about the many different methods of installing has shown you that install is really just shorthand for "copying files from one place to the appropriate places on your system." There's nothing mysterious about it. As long as you approach each install without expectations of how it's supposed to happen, and instead look for what the developer has set up as the install process, it's generally easy, even if it is different from what you're used to.
|
||||
|
||||
The important thing is that an installer is honest with you. If you come across an installer that attempts to install additional software without your consent (or maybe it asks for consent, but in a confusing or misleading way), or that attempts to run checks on your system for no apparent reason, then don't continue an install.
|
||||
|
||||
Good software is flexible, honest, and open. And now you know how to get good software onto your computer.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/1/how-install-apps-linux
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[1]:/file/382591
|
||||
[2]:https://opensource.com/sites/default/files/u128651/repo.png (Linux repository)
|
||||
[3]:https://fedoraproject.org/wiki/EPEL
|
||||
[4]:http://rpmfusion.org
|
||||
[5]:http://packman.links2linux.org/
|
||||
[6]:http://slackbuilds.org
|
||||
[7]:https://ring.cx/en/download/gnu-linux
|
||||
[8]:http://vivaldi.com
|
||||
[9]:/file/382566
|
||||
[10]:https://opensource.com/sites/default/files/u128651/access.png (Installing a repo)
|
||||
[11]:https://www.lwks.com/
|
||||
[12]:http://gog.com
|
||||
[13]:/file/382581
|
||||
[14]:https://opensource.com/sites/default/files/u128651/exec.jpg (Giving an installer executable permission)
|
||||
[15]:/file/382586
|
||||
[16]:https://opensource.com/sites/default/files/u128651/gog.jpg (GOG installer)
|
||||
[17]:/file/382576
|
||||
[18]:https://opensource.com/sites/default/files/u128651/appimage.png (AppImage system integration)
|
||||
[19]:https://opensource.com/article/17/7/how-unzip-targz-file
|
||||
[20]:/file/382596
|
||||
[21]:https://opensource.com/sites/default/files/u128651/twine.jpg (Twine downloaded for Linux)
|
||||
[22]:https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
|
||||
[23]:http://freedesktop.org
|
||||
[24]:https://opensource.com/article/17/10/open-source-cats
|
@ -0,0 +1,235 @@
|
||||
如何在 Linux 上安装应用程序
|
||||
=====
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux-penguins.png?itok=yKOpaJM_)
|
||||
|
||||
图片提供:Internet Archive Book Images。由 Opensource.com 修改。CC BY-SA 4.0
|
||||
|
||||
如何在 Linux 上安装应用程序?与有许多操作系统一样,这个问题不止有一个答案。应用程序可以可以来自许多来源-几乎不可能数的清,并且每个开发团队都可以以他们认为最好的方式提供软件。知道如何安装你所得到的软件是成为操作系统强大用户的一部分。
|
||||
|
||||
|
||||
### 仓库
|
||||
|
||||
十多年来,Linux 已经使用软件库来分发软件。在这种情况下,“仓库”是一个托管可安装软件包的公共服务器。Linux 发行版提供了一条命令,通常是该命令的图形界面,用于从服务器获取软件并将其安装到你的计算机。这是一个非常简单的概念,它已经成为所有主流手机操作系统的模型,最近,它也成为了两大闭源计算机操作系统的“应用商店”。
|
||||
|
||||
![Linux repository][2]
|
||||
|
||||
不是一个应用程序商店
|
||||
|
||||
从软件仓库安装是在 Linux 上安装应用程序的主要方法,它应该是你想要安装的任何应用程序的第一个地方。
|
||||
|
||||
从软件仓库安装,通常需要一个命令:
|
||||
```
|
||||
$ sudo dnf install inkscape
|
||||
```
|
||||
|
||||
实际使用的命令取决于你所使用的 Linux 发行版。Fedora 使用 `dnf`,OpenSUSE 使用 `zypper`,Debian 和 Ubuntu 使用 `apt`,Slackware 使用 `sbopkg`,FreeBSD 使用 `pkg_add`,而基于 lllumos 的 Openlndiana 使用 `pkg`。无论你使用什么,命令通常包括搜索你想要安装应用程序的正确名称,因为有时候你认为的软件名称不是它官方或单独的名称:
|
||||
```
|
||||
$ sudo dnf search pyqt
|
||||
|
||||
PyQt.x86_64 : Python bindings for Qt3
|
||||
|
||||
PyQt4.x86_64 : Python bindings for Qt4
|
||||
|
||||
python-qt5.x86_64 : PyQt5 is Python bindings for Qt5
|
||||
```
|
||||
一旦你找到要安装的软件包的名称后,使用 `install` 子命令执行实际的下载和自动安装:
|
||||
```
|
||||
$ sudo dnf install python-qt5
|
||||
```
|
||||
|
||||
有关从软件仓库安装的具体信息,请参阅你的 Linux 发行版的文档。
|
||||
|
||||
图形工具通常也是如此。搜索你认为你想要的,然后安装它。
|
||||
|
||||
![](https://opensource.com/sites/default/files/u128651/apper.png)
|
||||
|
||||
与底层命令一样,图形安装程序的名称取决于你正在运行的 Linux 发行版。相关应用程序通常使用软件或关键字进行标记,因此请在你的启动项或菜单中搜索这些条款,然后你将找到所需的内容。 由于开源是关于用户的选择,所以如果你不喜欢你的发行版提供的图形用户界面(GUI),那么你可以选择安装与否。 现在你知道如何做到这一点。
|
||||
|
||||
#### 额外仓库
|
||||
你的 Linux 发行版为其打包的软件提供了标准仓库,通常也有额外的仓库。例如,[EPEL][3] 服务于 Red Hat Enterprise Linux 和 CentOS,[RPMFusion][4] 服务于 Fedora,Ubuntu 有各种级别的支持以及个人包存档(PPA),[Packman][5] 为 OpenSUSE 提供额外的软件以及 [SlackBuilds.org][6] 为 Slackware 提供社区构建脚本。
|
||||
|
||||
默认情况下,你的 Linux 操作系统设置为只查看其官方仓库,因此如果你想使用其他软件集合,则必须自己添加额外库。你通常可以像安装软件包一样安装仓库。实际上,当你安装例如 [GNU Ring][7] 视频聊天,[Vivaldi][8] web 浏览器,谷歌浏览器等许多软件时,你实际安装的是访问他们的私人仓库,从中将最新版本的应用程序安装到你的机器上。
|
||||
|
||||
![Installing a repo][10]
|
||||
|
||||
建立一个仓库
|
||||
|
||||
你还可以通过编辑文本文件将仓库手动添加到软件包管理器的配置目录,或者运行命令来添加添加仓库。像往常一样,你使用的确切命令取决于 Linux 发行版本。例如,这是一个 `dnf` 命令,它将一个仓库添加到系统中:
|
||||
```
|
||||
$ sudo dnf config-manager --add-repo=http://example.com/pub/centos/7
|
||||
```
|
||||
|
||||
### 不使用仓库来安装应用程序
|
||||
|
||||
仓库模型非常流行,因为它提供了用户(你)和开发人员之间的链接。重要更新发布之后,系统会提示你接受更新,并且你可以从一个集中位置接受所有更新。
|
||||
|
||||
然而,有时候一个软件包没有附加的仓库可以使用。这些安装包有几种形式。
|
||||
|
||||
#### Linux 包
|
||||
|
||||
有时候,开发人员会以通用的 Linux 打包格式分发软件,例如 RPM,DEB 或较新但非常流行的 FlatPak 或 Snap 格式。你无法使用此下载访问仓库;你可能会得到这个包。
|
||||
|
||||
例如,视频编辑器 [Lightworks][11] 为 APT 用户提供了一个 `.deb` 文件,RPM 用户提供了 `.rpm` 文件。当你想要更新时,可以到网站下载最新的适合的文件。
|
||||
|
||||
这些一次性软件包可以使用从仓库进行安装时所用的所有工具进行安装。如果双击下载的软件包,图形安装程序将启动并逐步完成安装过程。
|
||||
|
||||
或者,你可以从终端进行安装。这里的区别在于你从互联网下载的独立包文件不是来自仓库。这是一个“本地”安装,这意味着你的软件安装包不需要下载来安装。大多数软件包管理器都是透明处理的:
|
||||
```
|
||||
$ sudo dnf install ~/Downloads/lwks-14.0.0-amd64.rpm
|
||||
```
|
||||
|
||||
在某些情况下,你需要采取额外的步骤才能使应用程序运行,因此请仔细阅读有关你正在安装软件的文档。
|
||||
|
||||
#### 通用安装
|
||||
|
||||
一些开发人员以几种通用格式发布他们的包。常见的扩展包括 `.run` 和 `.sh`。NVIDIA 显卡驱动程序,像 Nuke 和 Mari 这样的 Foundry visual FX 软件包以及来自 [GOG][12] 的许多无 DRM 游戏都是用这种安装程序。(译注:DRM 是数字版权管理。)
|
||||
|
||||
这种安装模式依赖于开发人员提供安装“向导”。一些安装程序是图形化的,而另一些只是在终端中运行。
|
||||
|
||||
有两种方式来运行这些类型的安装程序。
|
||||
|
||||
1. 你可以直接从终端运行安装程序:
|
||||
|
||||
```
|
||||
|
||||
$ sh ./game/gog_warsow_x.y.z.sh
|
||||
```
|
||||
2. 另外,你可以通过标记其为可执行文件来运行它。要标记为安装程序可执行文件,右键单击它的图标并选择 **Properties**。
|
||||
|
||||
![Giving an installer executable permission][14]
|
||||
|
||||
给安装程序可执行权限。
|
||||
|
||||
一旦你允许其运行,双击图标就可以安装了。
|
||||
|
||||
![GOG installer][16]
|
||||
|
||||
GOG 安装程序
|
||||
|
||||
对于其余的安装程序,只需要按照屏幕上的说明进行操作。
|
||||
|
||||
#### AppImage 便携式应用程序
|
||||
|
||||
AppImage 格式对于 Linux 相对来说比较新,尽管它的概念是基于 NeXT 和 Rox 的。这个想法很简单:运行应用程序所需的一切都应该放在一个目录中,然后该目录被视为一个“应用程序”。要运行该应用程序,只需双击该图标即可运行。没有必要或期望应用程序安装在传统意义的地方;它只是从你在硬盘上的任何地方运行。
|
||||
|
||||
尽管它可以作为独立应用运行,但 AppImage 通常提供一些系统集成。
|
||||
|
||||
![AppImage system integration][18]
|
||||
|
||||
AppImage 系统集成
|
||||
|
||||
如果你接受此条件,则将本地 `.desktop` 文件安装到你的主目录。`.desktop` 文件是 Linux 桌面的应用程序菜单和 mimetype 系统使用的一个小配置文件。实质上,将桌面配置文件放置在主目录的应用程序列表中“安装”应用程序,而不实际安装它。你获得了安装某些东西的所有好处,以及能够在本地运行某些东西的好处,例如“便携式应用程序”。
|
||||
|
||||
#### 应用程序目录
|
||||
|
||||
有时,开发人员只需要编译一个应用程序,然后将结果发布到下载中,没有安装脚本,也没有打包。通常,这意味着你下载了一个 TAR 文件,然后 [解压缩][19],然后双击可执行文件(通常是你下载软件的名称)。
|
||||
|
||||
|
||||
![Twine downloaded for Linux][21]
|
||||
|
||||
下载 Twine
|
||||
|
||||
当使用这种软件方式交付时,你可以将它放在你下载的地方,当你需要它时,你可以手动启动它,或者你可以自己进行快速但是麻烦的安装。这包括两个简单的步骤:
|
||||
|
||||
1. 将目录保存到一个标准位置,并在需要时手动启动它。
|
||||
2. 将目录保存到一个标准位置,并创建一个 `.desktop` 文件,将其集成到你的系统中。
|
||||
|
||||
如果你只是为自己安装应用程序,那么在你的主目录中保留 `bin` 目录(简称“二进制文件”)作为本地安装的应用程序和脚本的存储位置是传统意义上的。如果你的系统上有其他用户需要访问这些应用程序,传统上将二进制文件放置在 `/opt` 中。最后,这取决于你存储应用程序的位置。
|
||||
|
||||
下载通常以带版本名称的目录进行,如 `twine_2.13` 或者 `pcgen-v6.07.04`。由于可以合理地假设你将在某个时候更新应用程序,因此将版本号删除或创建目录的符号链接是个不错的主意。这样,即使你更新应用程序本身,为应用程序创建的启动程序也可以保持不变。
|
||||
|
||||
要创建一个 `.desktop` 启动文件,打开一个文本编辑器并创建一个名为 `twine.desktop` 的文件。[桌面条目规范][22] 由 [FreeDesktop.org][23] 定义。这是一个简单的启动器,用于一个名为 Twine 的游戏开发 IDE,安装在系统范围的 `/opt` 目录中:
|
||||
|
||||
```
|
||||
[Desktop Entry]
|
||||
|
||||
Encoding=UTF-8
|
||||
|
||||
Name=Twine
|
||||
|
||||
GenericName=Twine
|
||||
|
||||
Comment=Twine
|
||||
|
||||
Exec=/opt/twine/Twine
|
||||
|
||||
Icon=/usr/share/icons/oxygen/64x64/categories/applications-games.png
|
||||
|
||||
Terminal=false
|
||||
|
||||
Type=Application
|
||||
|
||||
Categories=Development;IDE;
|
||||
```
|
||||
|
||||
棘手的一行是 `Exec` 行。它必须包含一个有效的命令来启动应用程序。通常,它只是你下载的东西的完整路径,但在某些情况下,它更复杂一些。例如,Java 应用程序可能需要作为 Java 自身的参数启动。
|
||||
```
|
||||
Exec=java -jar /path/to/foo.jar
|
||||
```
|
||||
|
||||
有时,一个项目包含一个可以运行的包装脚本,这样你就不必找出正确的命令:
|
||||
```
|
||||
Exec=/opt/foo/foo-launcher.sh
|
||||
```
|
||||
|
||||
在这个 Twine 例子中,没有与下载捆绑的图标,因此示例 `.desktop` 文件指定了 KDE 桌面附带的通用游戏图标。你可以使用类似的解决方法,但如果你更具艺术性,这可以创建自己的图标,或者可以在 Internet 上搜索一个好的图标。只要 `Icon` 行指向一个有效的 PNG 或 SVG 文件,你的应用程序就会继承该图标。
|
||||
|
||||
示例脚本还将应用程序类别主要设置为 Development,因此在 KDE, GNOME 和大多数其他应用程序菜单中,Twine 出现在开发类别下。
|
||||
|
||||
为了让这个例子出现在应用程序菜单中,把 `twine.desktop` 文件放这到两个地方之一:
|
||||
|
||||
* 如果你将应用程序存储在你自己的家目录下,那么请将其放在 `~/.local/share/applications`。
|
||||
* 如果你将应用程序存储在 `/opt` 目录或者其他系统范围的位置,并希望它出现在所有用户的应用程序菜单中,请将它放在 `/usr/share/applications` 目录中。
|
||||
|
||||
现在,该应用程序已安装,因为它需要与系统的其他部分集成。
|
||||
|
||||
### 从源代码编译
|
||||
|
||||
最后,还有真正的通用格式安装格式:源代码。从源代码编译应用程序是学习如何构建应用程序,如何与系统交互以及如何定制应用程序的好方法。尽管如此,它绝不是一个按按钮式过程。它需要一个构建环境,通常需要安装依赖库和头文件,有时还要进行一些调试。
|
||||
|
||||
要了解更多关于从源代码编译的内容,请阅读[我这篇文章][24]。
|
||||
|
||||
### 现在你明白了
|
||||
|
||||
有些人认为安装软件是一个神奇的过程,只有开发人员理解,或者他们认为它“激活”了应用程序,就好像二进制可执行文件在“安装”之前无效。学习许多不同的安装方法会告诉你安装实际上只是“将文件从一个地方复制到系统中适当位置”的简写。 没有什么神秘的。只要你去了解每次安装,不是期望应该如何发生,并且寻找开发者为安装过程设置了什么,那么通常很容易,即使它与你的习惯不同。
|
||||
|
||||
重要的是安装人员对你很诚实。 如果你遇到未经你的同意尝试安装其他软件的安装程序(或者它可能会以混淆或误导的方式请求同意),或者尝试在没有明显原因的情况下对系统执行检查,则不要继续安装。
|
||||
|
||||
好的软件是灵活的,诚实的,开放的。 现在你知道如何在你的计算机上获得好的软件。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/1/how-install-apps-linux
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[1]:/file/382591
|
||||
[2]:https://opensource.com/sites/default/files/u128651/repo.png (Linux repository)
|
||||
[3]:https://fedoraproject.org/wiki/EPEL
|
||||
[4]:http://rpmfusion.org
|
||||
[5]:http://packman.links2linux.org/
|
||||
[6]:http://slackbuilds.org
|
||||
[7]:https://ring.cx/en/download/gnu-linux
|
||||
[8]:http://vivaldi.com
|
||||
[9]:/file/382566
|
||||
[10]:https://opensource.com/sites/default/files/u128651/access.png (Installing a repo)
|
||||
[11]:https://www.lwks.com/
|
||||
[12]:http://gog.com
|
||||
[13]:/file/382581
|
||||
[14]:https://opensource.com/sites/default/files/u128651/exec.jpg (Giving an installer executable permission)
|
||||
[15]:/file/382586
|
||||
[16]:https://opensource.com/sites/default/files/u128651/gog.jpg (GOG installer)
|
||||
[17]:/file/382576
|
||||
[18]:https://opensource.com/sites/default/files/u128651/appimage.png (AppImage system integration)
|
||||
[19]:https://opensource.com/article/17/7/how-unzip-targz-file
|
||||
[20]:/file/382596
|
||||
[21]:https://opensource.com/sites/default/files/u128651/twine.jpg (Twine downloaded for Linux)
|
||||
[22]:https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
|
||||
[23]:http://freedesktop.org
|
||||
[24]:https://opensource.com/article/17/10/open-source-cats
|
@ -1,26 +1,14 @@
|
||||
hankchow translating
|
||||
|
||||
Check Linux Distribution Name and Version
|
||||
查看 Linux 发行版名称和版本号的8种方法
|
||||
======
|
||||
You have joined new company and want to install some software’s which is requested by DevApp team, also want to restart few of the service after installation. What to do?
|
||||
如果你加入了一家新公司,要为开发团队安装所需的软件并重启服务,这个时候首先要弄清楚它们运行在什么发行版以及哪个版本的系统上,你才能正确完成后续的工作。作为系统管理员,充分了解系统信息是首要的任务。
|
||||
|
||||
In this situation at least you should know what Distribution & Version is running on it. It will help you perform the activity without any issue.
|
||||
查看 Linux 发行版名称和版本号有很多种方法。你可能会问,为什么要去了解这些基本信息呢?
|
||||
|
||||
Administrator should gather some of the information about the system before doing any activity, which is first task for him.
|
||||
因为对于诸如 RHEL、Debian、openSUSE、Arch Linux 这几种主流发行版来说,它们各自拥有不同的包管理器来管理系统上的软件包,如果不知道所使用的是哪一个发行版的系统,在包安装的时候就会无从下手,而且由于大多数发行版都是用 systemd 命令而不是 SysVinit 脚本,在重启服务的时候也难以执行正确的命令。
|
||||
|
||||
There are many ways to find the Linux distribution name and version. You might ask, why i want to know this basic things?
|
||||
下面来看看可以使用那些基本命令来查看 Linux 发行版名称和版本号。
|
||||
|
||||
We have four major distributions such as RHEL, Debian, openSUSE & Arch Linux. Each distribution comes with their own package manager which help us to install packages on the system.
|
||||
|
||||
If you don’t know the distribution name then you wont be able to perform the package installation.
|
||||
|
||||
Also you won’t able to run the proper command for service bounces because most of the distributions implemented systemd command instead of SysVinit script.
|
||||
|
||||
It’s good to have the basic commands which will helps you in many ways.
|
||||
|
||||
Use the following Methods to Check Your Linux Distribution Name and Version.
|
||||
|
||||
### List of methods
|
||||
### 方法总览
|
||||
|
||||
* lsb_release command
|
||||
* /etc/*-release file
|
||||
@ -33,9 +21,10 @@ Use the following Methods to Check Your Linux Distribution Name and Version.
|
||||
|
||||
|
||||
|
||||
### Method-1: lsb_release Command
|
||||
### 方法1: lsb_release 命令
|
||||
|
||||
LSB(Linux Standard Base,Linux 标准库)能够打印发行版的具体信息,包括发行版名称、版本号、代号等。
|
||||
|
||||
LSB stands for Linux Standard Base that prints distribution-specific information such as Distribution name, Release version and codename.
|
||||
```
|
||||
# lsb_release -a
|
||||
No LSB modules are available.
|
||||
@ -46,11 +35,10 @@ Codename: xenial
|
||||
|
||||
```
|
||||
|
||||
### Method-2: /etc/arch-release /etc/os-release File
|
||||
### 方法2: /etc/arch-release /etc/os-release File
|
||||
|
||||
release file typically known as Operating system identification. The `/etc` directory contains many files that contains various information about the distribution. Each distribution has their own set of files, which display this information.
|
||||
版本文件通常被视为操作系统的标识。在 `/etc` 目录下放置了很多记录着发行版各种信息的文件,每个发行版都各自有一套这样记录着相关信息的文件。下面是一组在 Ubuntu/Debian 系统上显示出来的文件内容。
|
||||
|
||||
The below set of files are present on Ubuntu/Debian system.
|
||||
```
|
||||
# cat /etc/issue
|
||||
Ubuntu 16.04.3 LTS \n \l
|
||||
@ -82,7 +70,7 @@ UBUNTU_CODENAME=xenial
|
||||
|
||||
```
|
||||
|
||||
The below set of files are present on RHEL/CentOS/Fedora system. The `/etc/redhat-release` & `/etc/system-release` files symlinks with `/etc/[distro]-release` file.
|
||||
下面这一组是在 RHEL/CentOS/Fedora 系统上显示出来的文件内容。其中 `/etc/redhat-release` 和 `/etc/system-release` 文件是指向 `/etc/[发行版名称]-release` 文件的一个连接。
|
||||
```
|
||||
# cat /etc/centos-release
|
||||
CentOS release 6.9 (Final)
|
||||
@ -115,34 +103,34 @@ Fedora release 27 (Twenty Seven)
|
||||
|
||||
```
|
||||
|
||||
### Method-3: uname Command
|
||||
### 方法3: uname 命令
|
||||
|
||||
uname (stands for unix name) is an utility that prints the system information like kernel name, version and other details about the system and the operating system running on it.
|
||||
uname(unix name) 是一个打印系统信息的工具,包括内核名称、版本号、系统详细信息以及所运行的操作系统等等。
|
||||
|
||||
**Suggested Read :** [6 Methods To Check The Running Linux Kernel Version On System][1]
|
||||
**建议阅读:** [6种查看系统 Linux 内核的方法][1]
|
||||
```
|
||||
# uname -a
|
||||
Linux localhost.localdomain 4.12.14-300.fc26.x86_64 #1 SMP Wed Sep 20 16:28:07 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
|
||||
|
||||
```
|
||||
|
||||
The above colored words describe the version of operating system as Fedora Core 26.
|
||||
以上运行结果说明使用的操作系统版本是 Fedora 26。
|
||||
|
||||
### Method-4: /proc/version File
|
||||
### 方法4: /proc/version File
|
||||
|
||||
This file specifies the version of the Linux kernel, the version of gcc used to compile the kernel, and the time of kernel compilation. It also contains the kernel compiler’s user name (in parentheses).
|
||||
这个文件记录了 Linux 内核的版本、用于编译内核的 gcc 的版本、内核编译的时间,以及内核编译者的用户名。
|
||||
```
|
||||
# cat /proc/version
|
||||
Linux version 4.12.14-300.fc26.x86_64 ([email protected]) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) ) #1 SMP Wed Sep 20 16:28:07 UTC 2017
|
||||
Linux version 4.12.14-300.fc26.x86_64 ([email protected]) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) ) #1 SMP Wed Sep 20 16:28:07 UTC 2017
|
||||
|
||||
```
|
||||
|
||||
### Method-5: dmesg Command
|
||||
### Method-5: dmesg 命令
|
||||
|
||||
dmesg (stands for display message or driver message) is a command on most Unix-like operating systems that prints the message buffer of the kernel.
|
||||
dmesg(display message/driver message,展示信息/驱动程序信息)是大多数类 Unix 操作系统上的一个命令,用于打印内核上消息缓冲区的信息。
|
||||
```
|
||||
# dmesg | grep "Linux"
|
||||
[ 0.000000] Linux version 4.12.14-300.fc26.x86_64 ([email protected]) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) ) #1 SMP Wed Sep 20 16:28:07 UTC 2017
|
||||
[ 0.000000] Linux version 4.12.14-300.fc26.x86_64 ([email protected]) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) ) #1 SMP Wed Sep 20 16:28:07 UTC 2017
|
||||
[ 0.001000] SELinux: Initializing.
|
||||
[ 0.001000] SELinux: Starting in permissive mode
|
||||
[ 0.470288] SELinux: Registering netfilter hooks
|
||||
@ -154,11 +142,11 @@ dmesg (stands for display message or driver message) is a command on most Unix-l
|
||||
|
||||
```
|
||||
|
||||
### Method-6: Yum/Dnf Command
|
||||
### Method-6: Yum/Dnf 命令
|
||||
|
||||
Yum (Yellowdog Updater Modified) is one of the package manager utility in Linux operating system. Yum command is used to install, update, search & remove packages on some Linux distributions based on RedHat.
|
||||
Yum(Yellowdog Updater Modified)是 Linux 操作系统上的一个包管理工具,而 `yum` 命令则是一些基于 RedHat 的 Linux 发行版上用于安装、更新、查找、删除软件包的命令。
|
||||
|
||||
**Suggested Read :** [YUM Command To Manage Packages on RHEL/CentOS Systems][2]
|
||||
**建议阅读:** [在 RHEL/CentOS 系统上使用 yum 命令管理软件包][2]
|
||||
```
|
||||
# yum info nano
|
||||
Loaded plugins: fastestmirror, ovl
|
||||
@ -180,7 +168,7 @@ Description : GNU nano is a small and friendly text editor.
|
||||
|
||||
```
|
||||
|
||||
The below yum repolist command shows that Base, Extras, and Updates repositories are coming from CentOS 7 repository.
|
||||
下面的 `yum repolist` 命令执行后显示了 yum 的基础源仓库、额外源仓库、更新源仓库都来自 CentOS 7 仓库。
|
||||
```
|
||||
# yum repolist
|
||||
Loaded plugins: fastestmirror, ovl
|
||||
@ -196,9 +184,9 @@ repolist: 11908
|
||||
|
||||
```
|
||||
|
||||
We can also use Dnf command to check distribution name and version.
|
||||
使用 `dnf` 命令也同样可以查看发行版名称和版本号。
|
||||
|
||||
**Suggested Read :** [DNF (Fork of YUM) Command To Manage Packages on Fedora System][3]
|
||||
**建议阅读:** [在 Fedora 系统上使用 DNF(YUM 的一个分支)命令管理软件包][3]
|
||||
```
|
||||
# dnf info nano
|
||||
Last metadata expiration check: 0:01:25 ago on Thu Feb 15 01:59:31 2018.
|
||||
@ -218,22 +206,22 @@ Description : GNU nano is a small and friendly text editor.
|
||||
|
||||
```
|
||||
|
||||
### Method-7: RPM Command
|
||||
### Method-7: RPM 命令
|
||||
|
||||
RPM stands for RedHat Package Manager is a powerful, command line Package Management utility for Red Hat based system such as CentOS, Oracle Linux & Fedora. This help us to identify the running system version.
|
||||
RPM(RedHat Package Manager, RedHat 包管理器)是在 CentOS、Oracle Linux、Fedora 这些基于 RedHat 的操作系统上的一个强大的命令行包管理工具,同样也可以帮助我们查看系统的版本信息。
|
||||
|
||||
**Suggested Read :** [RPM commands to manage packages on RHEL based systems][4]
|
||||
**建议阅读:** [在基于 RHEL 的系统上使用 RPM 命令管理软件包][4]
|
||||
```
|
||||
# rpm -q nano
|
||||
nano-2.8.7-1.fc27.x86_64
|
||||
|
||||
```
|
||||
|
||||
### Method-8: APT-GET Command
|
||||
### Method-8: APT-GET 命令
|
||||
|
||||
Apt-Get stands for Advanced Packaging Tool (APT). apg-get is a powerful command-line tool which is used to automatically download and install new software packages, upgrade existing software packages, update the package list index, and to upgrade the entire Debian based systems.
|
||||
Apt-Get(Advanced Packaging Tool)是一个强大的命令行工具,可以自动下载安装新软件包、更新已有的软件包、更新软件包列表索引,甚至更新整个 Debian 系统。
|
||||
|
||||
**Suggested Read :** [Apt-Get & Apt-Cache commands to manage packages on Debian Based Systems][5]
|
||||
**建议阅读:** [在基于 Debian 的系统上使用 Apt-Get 和 Apt-Cache 命令管理软件包][5]
|
||||
```
|
||||
# apt-cache policy nano
|
||||
nano:
|
||||
@ -253,7 +241,7 @@ nano:
|
||||
via: https://www.2daygeek.com/check-find-linux-distribution-name-and-version/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[HankChow](https://github.com/HankChow)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user