使用 Topgrade 一次升级 Linux 中的各种软件包
更新 软件包
![](/data/attachment/album/202210/12/152118mo5r6pohnn4o5h56.jpg)


更新 Linux 系统并没有那么复杂，不是吗？毕竟，要更新 Ubuntu 之类的发行版，你只需要使用 `apt update` 和 `apt upgrade` 就行。


如果所有的包都是通过一个包管理器安装的，就会是这样。


但现在情况不再如此。你有经典的 apt/dnf/pacman，还有 Snap、Flatpak、Appimages。不止于此，你还可以使用 PIP（用于 Python）和 Cargo（用于 Rust）安装应用。


使用 Node？ NPM 包需要单独更新。Oh My Zsh？需要单独更新。[Vim 中的插件](https://linuxhandbook.com/install-vim-plugins/)、Atom 等也可能不被 apt/dnf/pacman 覆盖。


你现在看到问题了吗？这就是名为 Topgrade 的新工具旨在解决的问题。


### Topgrade：处理各种更新的单一程序


[Topgrade](https://github.com/r-darwish/topgrade) 是一个 CLI 程序，它会检测你使用的工具，然后运行适当的命令来更新它们。


![Topgrade disable system](/data/attachment/album/202210/12/152120q9kktzhly9tgjmb2.png)


除了通常的 Linux 包管理器，它还可以检测和更新 Brew、Cargo、PIP、Pihole、Vim 和 Emacs 插件、R 软件包等。你可以在 [维基页面](https://github.com/r-darwish/topgrade/wiki/Step-list) 上查看支持的包列表。


##### Topgrade 的主要特点：


* 能够更新来自不同的包管理器的软件包，**包括固件**！
* 你可以如何控制更新包。
* 高度可定制。
* 甚至能够在更新包之前进行概览。


所以不要浪费任何时间，让我们跳到安装。


### 使用 Cargo 在 Linux 中安装 Topgrade


安装过程非常简单，因为我将使用 Cargo 包管理器。


我们已经有了 [详细指南，其中包含设置 Cargo 包管理器的多种方法](https://itsfoss.com/install-rust-cargo-ubuntu-linux/)。所以我将在我的示例中使用 Ubuntu 来快速完成。


因此，让我们以最少方式安装依赖项以及 Cargo：



```
sudo apt install cargo libssl-dev pkg-config

```

安装 Cargo 后，使用给定的命令安装 Topgrade：



```
cargo install topgrade

```

它会抛出一个警告：


![cargo error](/data/attachment/album/202210/12/152120naa5q222rrp29n7p.png)


你只需添加 `cargo` 路径即可运行二进制文件。这可以通过给定的命令来完成，你需要使用你的用户名替换 `sagar`：



```
echo 'export PATH=$PATH:/home/sagar/.cargo/bin' >> /home/sagar/.bashrc

```

现在，重启系统，Topgrade 就可以使用了。但是等等，我们需要安装另一个包来更新 Cargo 以获取最新的包。



```
cargo install cargo-update

```

这样我们完成了安装。


### 使用 Topgrade


使用 Topgrade 非常简单。使用一个命令，就是这样：



```
topgrade

```





但这不会给你除了系统包之外的任何控制，但正如我所提到的，你可以将不想更新的仓库列入黑名单。


#### 从 Topgrade 中排除包管理器和仓库


假设我想排除 Snap 和从默认包管理器下载的包，所以我的命令是：



```
topgrade --disable snap system

```

![Topgrade disable snap system](/data/attachment/album/202210/12/152121t3ivtpj5z3p8w3w5.png)


要进行永久更改，你必须在其配置文件中进行一些更改，这些更改可以通过给定的命令访问：



```
topgrade --edit-config

```

对于此示例，我排除了 Snap 和默认系统仓库：


![configuring Topgrade](/data/attachment/album/202210/12/152121hbh8wv114eekm0k4.png)


#### 试运行 Topgrade


评估将要更新的过时软件包总是一个好主意，我从 Topgrade 的整个目录中找到了这个最有用的选项。


你只需使用带有 `-n` 选项的 `topgrade` 命令，它就会生成过期软件包的摘要。



```
topgrade -n

```

![summery of Topgrade](/data/attachment/album/202210/12/152121m29c42zm7y77721h.png)


检查需要更新的软件包的一种简洁方法。


### 总结


在使用 Topgrade 几周后，它成为了我的 Linux 武器库中不可或缺的一部分。 像大多数其他 Linux 用户一样，我只是通过我的默认包管理器更新包。 Python 和 Rust 包被完全忽略了。 感谢 Topgrade，我的系统现在完全更新了。


我知道这不是每个人都想使用的工具。那你呢？愿意试一试吗？




---


via: <https://itsfoss.com/topgrade/>


作者：[Sagar Sharma](https://itsfoss.com/author/sagar/) 选题：[lkxed](https://github.com/lkxed) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

Updating a Linux system is not that complicated, is it? After all, to update Ubuntu-like distros, you just have to use apt update && apt upgrade.

That would have been the case if all the packages had been installed through a single package manager.

But that’s not the case anymore. You have the classic apt/dnf/pacman and then come Snap, Flatpak, and AppImage files. It doesn’t end here...

You may also install applications using PIP (for Python) and Cargo (for Rust) as well.

Use Node.js? The npm packages need to be updated separately. And, **Oh My Zsh?** It needs to be updated separately too.

[Plugins in Vim](https://linuxhandbook.com/install-vim-plugins/), Atom, etc, may also not be covered by apt/dnf/pacman.

Do you see the problem now? It may not be convenient to update all packages in your system. This is the problem a new tool called **topgrade** aims to solve.

## Topgrade: A single utility to take care of all kinds of updates

This [topgrade](https://github.com/topgrade-rs/topgrade) is a CLI utility that detects which tools you use and then runs the appropriate commands to update them.

![topgrade disable system](https://itsfoss.com/content/images/wordpress/2022/09/topgrade-disable-system.png)

Apart from the usual Linux package managers, it can detect and update brew, cargo, PIP, pihole, Vim and Emacs plugins, R packages etc.

You can explore its [GitHub page](https://github.com/topgrade-rs/topgrade) to know more.

#### Key Features of Topgrade:

- Ability to update packages from different package managers,
**including firmware!** - You do have control over how you want to update packages.
- Extremely customizable.
- Ability to have an overview even before updating packages.

So without wasting any time, let’s jump to the installation.

## Install Topgrade in Linux using Cargo

The installation process is quite straightforward as I’m going to use the cargo package manager.

We already have a [detailed guide with multiple methods for setting up a cargo package manager](https://itsfoss.com/install-rust-cargo-ubuntu-linux/) So I’m going to make it quick by using Ubuntu in my example.

So let’s start with some dependencies and installation of cargo in the least extensive way:

`sudo apt install cargo libssl-dev pkg-config`


Once the cargo has been installed, utilize the given command to install topgrade:

`cargo install topgrade`


And it will throw a warning as given:

![cargo error](https://itsfoss.com/content/images/wordpress/2022/09/cargo-error.png)

Where you just have to add the path of cargo to run binaries. This can be done through given command where you’ve to change `sagar`

with your username:

`echo 'export PATH=$PATH:/home/sagar/.cargo/bin' >> /home/sagar/.bashrc`


Now, reboot your system and topgrade is ready to use. But wait, we need to install another package that will update cargo to get the most recent packages.

`cargo install cargo-update`


And we’re done with installation.

## Using Topgrade

Using topgrade is extremely easy. Use a single command and that’s it:

`topgrade`


But this won’t give you any control apart from system packages, but as I mentioned, you can blacklist the repo you don’t want to get updated.

### Exclude package managers and repositories from Topgrade

Let’s suppose I want to exclude snaps and packages downloaded from the default package manager, so my command would be:

`topgrade --disable snap system`


![topgrade disable snap system](https://itsfoss.com/content/images/wordpress/2022/09/topgrade-disable-snap-system.png)

For making a permanent change, you’d have to make a few changes in its config file which can be accessed through the given command:

`topgrade --edit-config`


For this example, I discluded snaps and default system repo:

![configuring topgrade](https://itsfoss.com/content/images/wordpress/2022/09/configuring-topgrade-1-800x527.png)


![configuring topgrade](https://itsfoss.com/content/images/wordpress/2022/09/configuring-topgrade-1-800x527.png)

### Dry run topgrade

Having an estimation of outdated packages that will be updated is always a good idea and I find this most useful option from the entire catalog of topgrade.

You just have to use topgrade with `-n`

option and it will generate a summary of outdated packages.

`topgrade -n`


![summery of topgrade](https://itsfoss.com/content/images/wordpress/2022/09/summery-of-topgrade.png)

A neat way of checking packages that need to be updated.

## Final Words

After using Topgrade for a few weeks, it became an integral part of my Linux arsenal. Like most other Linux users, I only updated packages through my default package manager. Python and Rust packages were ignored completely. Thanks to topgrade, my system is updated entirely now.

I understand that this is not a tool everyone would want to use. What about you? Willing to give it a try?