From 0aedd6d838c8f755bf7f8fee98923009885cba21 Mon Sep 17 00:00:00 2001 From: geekpi Date: Tue, 17 Oct 2023 08:57:01 +0800 Subject: [PATCH] translated --- ...ckage Manager on non-Nix OS like Ubuntu.md | 237 ------------------ ...ckage Manager on non-Nix OS like Ubuntu.md | 232 +++++++++++++++++ 2 files changed, 232 insertions(+), 237 deletions(-) delete mode 100644 sources/tech/20231015 Install and Use Nix Package Manager on non-Nix OS like Ubuntu.md create mode 100644 translated/tech/20231015 Install and Use Nix Package Manager on non-Nix OS like Ubuntu.md diff --git a/sources/tech/20231015 Install and Use Nix Package Manager on non-Nix OS like Ubuntu.md b/sources/tech/20231015 Install and Use Nix Package Manager on non-Nix OS like Ubuntu.md deleted file mode 100644 index eb3220ddbc..0000000000 --- a/sources/tech/20231015 Install and Use Nix Package Manager on non-Nix OS like Ubuntu.md +++ /dev/null @@ -1,237 +0,0 @@ -[#]: subject: "Install and Use Nix Package Manager on non-Nix OS like Ubuntu" -[#]: via: "https://itsfoss.com/ubuntu-install-nix-package-manager/" -[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/" -[#]: collector: "lujun9972/lctt-scripts-1693450080" -[#]: translator: "geekpi" -[#]: reviewer: " " -[#]: publisher: " " -[#]: url: " " - -Install and Use Nix Package Manager on non-Nix OS like Ubuntu -====== - -One of the reasons [why people like using the immutable NixOS][1] is its Nix package manager. - -It has over 80,000 packages, which might not be close to the number of Debian packages but pretty impressive nonetheless. - -The good thing is that you don't have to [install NixOS][2] just for the package manager. Like [Homebrew][3] and Rust's [Cargo package manager][4], you can use Nix package manager in your present distribution. - -Why would you do that? Because sometimes, you may find a new application that is only available in Nix packaging format. It's rare but possible. - -In this tutorial, I will walk you through the following: - - * Installing Nix package manager - * Searching and installing packages - * Try/test packages without installing them - * Update packages - * Removing packages - - - -### Install Nix package manager on other Linux distros - -There are two ways to install the Nix package manager: global install and local install. - -📋 - -The global install means the nix package manager will be accessible by every user available on the system, whereas the local installation is only for the current user. The [official Nix documentation][5] recommends you use the global install. - -##### For global installation: - -If you want to install the Nix package manager globally, then, you need to execute the following command: - -``` - - sh <(curl -L https://nixos.org/nix/install) --daemon - -``` - -Once you execute the above command, you need to enter the `y` key and press the `Enter` key: - -![][6] - -Once done, close the current terminal as it won't work on the current terminal session. - -##### For local installation: - -If you prefer the local installation and don't want to use sudo every time, then execute the following command: - -``` - - sh <(curl -L https://nixos.org/nix/install) --no-daemon - -``` - -Enter `y` and press the `Enter` key when asked for the confirmation. - -Once done, close the current terminal session and start a new one to use the Nix package manager. - -### Search and install packages - -Once you have installed the Nix package manager, the next step is to search for packages. - -First, [visit the official page of Nix search][7] and type the name of the package that you want to install. - -From the given description, you can find the package which you were looking for and then, choose the `nix-env` to go with the permanent installation. - -Here, you can add some extra keywords to have better search results. For example, here, I searched for "Firefox browser": - -![][8] - -The last step that I mentioned above (copy command) does nothing but gives you a command that you execute for the installation. - -Now, all you have to do is execute that command in your terminal. - -In my case, it gave me the following command to install Firefox: - -``` - - nix-env -iA nixpkgs.firefox - -``` - -Once done, you can list the installed packages using the following command: - -``` - - nix-env -q - -``` - -![][9] - -### Use packages without installing them - -By far this is the best feature of the Nix package manager as you get to use/test packages that are not even installed! - -For this, you can use the nix shell which lets you use an interactive shell with the specified package, and once closed, you can no longer access that package. - -Cool, right? - -To use the nix-shell to access your favorite package, use the following command syntax: - -``` - - nix-shell -p - -``` - -For example, I wanted to use neofetch once, so I used the following: - -``` - - nix-shell -p neofetch - -``` - -![][10] - -To exit from the shell, all you have to do is execute the `exit` command: - -``` - - exit - -``` - -### Update packages using the Nix package manager - -Updating packages using the Nix package manager is pretty easy. - -To update packages, first, you need to update channels using the following command: - -``` - - nix-channel --update - -``` - -Next, you can list the outdated packages by dry-running the update command: - -``` - - nix-env --upgrade --dry-run - -``` - -![][11] - -In my case, the Firefox browser was outdated and needs to be updated! - -To update a single package, use the following command: - -``` - - nix-env -u - -``` - -And if you want to update all the packages at once, then use the following: - -``` - - nix-env -u - -``` - -### Remove packages using the Nix package manager - -To remove packages, all you have to do is execute the `nix-env` command in the following manner: - -``` - - nix-env --uninstall [package_name] - -``` - -For example, if I want to remove the Firefox browser, then, I will use the following command: - -``` - - nix-env --uninstall firefox - -``` - -![][12] - -### Unlock its full potential with NixOS - -If you liked the idea behind the Nix package manager, trust me, you're going to love the [NixOS][13]. - -Reproducing the entire system just by using one config file was enough to convince me to make a switch to NixOS but there are more reasons: - -![][14] - -I love NixOS. So much so that I wrote a whole series so you don't have to go through documentation (for basics): - -![][14] - -I hope you will enjoy using it as much as I do. - --------------------------------------------------------------------------------- - -via: https://itsfoss.com/ubuntu-install-nix-package-manager/ - -作者:[Sagar Sharma][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://itsfoss.com/author/sagar/ -[b]: https://github.com/lujun9972 -[1]: https://itsfoss.com/why-use-nixos/ -[2]: https://itsfoss.com/install-nixos-vm/ -[3]: https://itsfoss.com/homebrew-linux/ -[4]: https://itsfoss.com/install-rust-cargo-ubuntu-linux/ -[5]: https://nixos.org/learn -[6]: https://itsfoss.com/content/images/2023/10/Install-nix-package-manager-globally.png -[7]: https://search.nixos.org/packages -[8]: https://itsfoss.com/content/images/2023/10/Search-packages-to-install-using-the-Nix-package-manager.png -[9]: https://itsfoss.com/content/images/2023/10/List-installed-packages-using-the-nix-package-manager.png -[10]: https://itsfoss.com/content/images/2023/10/Use-packages-wihout-installing-them-using-the-nix-package-manager.png -[11]: https://itsfoss.com/content/images/2023/10/List-outdated-packages-using-the-nix-package-manager.png -[12]: https://itsfoss.com/content/images/2023/10/Remove-packages-using-the-nix-package-manager-1.png -[13]: https://nixos.org/ -[14]: https://itsfoss.com/content/images/size/w256h256/2022/12/android-chrome-192x192.png diff --git a/translated/tech/20231015 Install and Use Nix Package Manager on non-Nix OS like Ubuntu.md b/translated/tech/20231015 Install and Use Nix Package Manager on non-Nix OS like Ubuntu.md new file mode 100644 index 0000000000..c802920fec --- /dev/null +++ b/translated/tech/20231015 Install and Use Nix Package Manager on non-Nix OS like Ubuntu.md @@ -0,0 +1,232 @@ +[#]: subject: "Install and Use Nix Package Manager on non-Nix OS like Ubuntu" +[#]: via: "https://itsfoss.com/ubuntu-install-nix-package-manager/" +[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/" +[#]: collector: "lujun9972/lctt-scripts-1693450080" +[#]: translator: "geekpi" +[#]: reviewer: " " +[#]: publisher: " " +[#]: url: " " + +在 Ubuntu 等非 Nix 操作系统上安装和使用 Nix 包管理器 +====== + +[人们喜欢使用不可变的 NixOS][1] 的原因之一是它的 Nix 包管理器。 + +它有超过 80,000 个软件包,这可能与 Debian 软件包的数量不太接近,但仍然令人印象深刻。 + +好处是你不必仅仅为了包管理器而[安装 NixOS][2]。与 [Homebrew][3] 和 Rust 的 [Cargo 包管理器][4] 一样,你可以在当前发行版中使用 Nix 包管理器。 + +为什么要这么做? 因为有时,你可能会发现仅以 Nix 打包格式提供的新应用。这种情况很少见,但有可能。 + +在本教程中,我将引导你完成以下内容: + + * 安装 Nix 包管理器 + * 搜索并安装包 + * 尝试/测试软件包而不安装它们 + * 更新包 + * 删除包 + + + +### 在其他 Linux 发行版上安装 Nix 包管理器 + +Nix 包管理器有两种安装方式:全局安装和本地安装。 + +📋 + +全局安装意味着系统上的每个可用用户都可以访问 nix 包管理器,而本地安装仅适用于当前用户。[Nix 官方文档][5] 建议你使用全局安装。 + +##### 对于全局安装: + +如果你想全局安装Nix包管理器,那么,你需要执行以下命令: + +```` + + sh <(curl -L https://nixos.org/nix/install) --daemon + +```` + +执行上述命令后,需要输入 `y` 键并按`回车`键: + +![][6] + +完成后,关闭当前终端,因为它不会在当前终端会话上运行。 + +##### 对于本地安装: + +如果你更喜欢本地安装并且不想每次都使用 sudo,则执行以下命令: + +```` + + sh <(curl -L https://nixos.org/nix/install) --no-daemon + +```` + +输入 `y` 并在要求确认时按`回车`键。 + +完成后,关闭当前终端会话并启动一个新终端会话以使用 Nix 包管理器。 + +### 搜索并安装包 + +安装 Nix 包管理器后,下一步是搜索包。 + +首先,[访问 Nix 搜索的官方页面][7]并输入你要安装的软件包的名称。 + +从给定的描述中,你可以找到所需的软件包,然后选择 `nix-env` 进行永久安装。 + +在这里,你可以添加一些额外的关键字以获得更好的搜索结果。例如,在这里,我搜索 “Firefox browser”: + +![][8] + +我上面提到的最后一步(复制命令)什么也不做,只是为你提供了一个用于安装的命令。 + +现在,你所要做的就是在终端中执行该命令。 + +就我而言,它给了我以下命令来安装 Firefox: + +```` + + nix-env -iA nixpkgs.firefox + +```` + +完成后,你可以使用以下命令列出已安装的软件包: + +```` + + nix-env -q + +```` + +![][9] + +### 使用包而不安装它们 + +到目前为止,这是 Nix 包管理器的最佳功能,因为你可以使用/测试包甚至不用安装它! + +为此,你可以使用 nix shell,它允许你将交互式 shell 与指定的包一起使用,关闭后,你将无法再访问该包。 + +很酷,对吧? + +要使用 nix-shell 访问你喜欢的软件包,请使用以下命令语法: + +```` + + nix-shell -p + +```` + +例如,我想使用一次 neofetch,所以我使用了以下命令: + +```` + + nix-shell -p neofetch + +```` + +![][10] + +要退出 shell,你所要做的就是执行 `exit` 命令: + +```` + + exit + +```` + +### 使用 Nix 包管理器更新包 + +使用 Nix 包管理器更新包非常简单。 + +要更新软件包,首先,你需要使用以下命令更新频道: + +```` + + nix-channel --update + +```` + +接下来,你可以通过空运行更新命令来列出过时的软件包: + +```` + + nix-env --upgrade --dry-run + +```` + +![][11] + +就我而言,Firefox 浏览器已经过时,需要更新! + +要更新单个包,请使用以下命令: + +```` + + nix-env -u + +```` + +如果你想一次更新所有软件包,请使用以下命令: + +```` + + nix-env -u + +```` + +### 使用 Nix 包管理器删除包 + +要删除软件包,你只需按以下方式执行 `nix-env` 命令即可: + +```` + + nix-env --uninstall [package_name] + +```` + +例如,如果我想删除 Firefox 浏览器,那么,我将使用以下命令: + +```` + + nix-env --uninstall firefox + +```` + +![][12] + +### 通过 NixOS 释放其全部潜力 + +如果你喜欢 Nix 包管理器背后的想法,请相信我,你一定会喜欢 [NixOS][13]。 + +仅使用一个配置文件来复制整个系统就足以说服我切换到 NixOS,但还有更多原因: + +我喜欢 NixOS。以至于我写了整个系列,这样你就不必阅读文档(基础知识): + +我希望你能像我一样喜欢使用它。 + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/ubuntu-install-nix-package-manager/ + +作者:[Sagar Sharma][a] +选题:[lujun9972][b] +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://itsfoss.com/author/sagar/ +[b]: https://github.com/lujun9972 +[1]: https://itsfoss.com/why-use-nixos/ +[2]: https://itsfoss.com/install-nixos-vm/ +[3]: https://itsfoss.com/homebrew-linux/ +[4]: https://itsfoss.com/install-rust-cargo-ubuntu-linux/ +[5]: https://nixos.org/learn +[6]: https://itsfoss.com/content/images/2023/10/Install-nix-package-manager-globally.png +[7]: https://search.nixos.org/packages +[8]: https://itsfoss.com/content/images/2023/10/Search-packages-to-install-using-the-Nix-package-manager.png +[9]: https://itsfoss.com/content/images/2023/10/List-installed-packages-using-the-nix-package-manager.png +[10]: https://itsfoss.com/content/images/2023/10/Use-packages-wihout-installing-them-using-the-nix-package-manager.png +[11]: https://itsfoss.com/content/images/2023/10/List-outdated-packages-using-the-nix-package-manager.png +[12]: https://itsfoss.com/content/images/2023/10/Remove-packages-using-the-nix-package-manager-1.png +[13]: https://nixos.org/ \ No newline at end of file