❏ 站外平台:

如何在 Linux 中不安装软件测试一个软件包

作者: Sk 译者: LCTT geekpi

| 2018-06-16 22:57   收藏: 1    

出于某种原因,你可能需要在将软件包安装到你的 Linux 系统之前对其进行测试。如果是这样,你很幸运!今天,我将向你展示如何在 Linux 中使用 Nix 包管理器来实现。Nix 包管理器的一个显著特性是它允许用户测试软件包而无需先安装它们。当你想要临时使用特定的程序时,这会很有帮助。

测试一个软件包而不在 Linux 中安装它

确保你先安装了 Nix 包管理器。如果尚未安装,请参阅以下指南。

例如,假设你想测试你的 C++ 代码。你不必安装 GCC。只需运行以下命令:

  1. $ nix-shell -p gcc

该命令会构建或下载 gcc 软件包及其依赖项,然后将其放入一个存在 gcc 命令的 Bash shell 中,所有这些都不会影响正常环境。

  1. LANGUAGE = (unset),
  2. LC_ALL = (unset),
  3. LANG = "en_US.UTF-8"
  4. are supported and installed on your system.
  5. perl: warning: Falling back to the standard locale ("C").
  6. download-using-manifests.pl: perl: warning: Setting locale failed.
  7. download-using-manifests.pl: perl: warning: Please check that your locale settings:
  8. download-using-manifests.pl: LANGUAGE = (unset),
  9. download-using-manifests.pl: LC_ALL = (unset),
  10. download-using-manifests.pl: LANG = "en_US.UTF-8"
  11. download-using-manifests.pl: are supported and installed on your system.
  12. download-using-manifests.pl: perl: warning: Falling back to the standard locale ("C").
  13. download-from-binary-cache.pl: perl: warning: Setting locale failed.
  14. download-from-binary-cache.pl: perl: warning: Please check that your locale settings:
  15. download-from-binary-cache.pl: LANGUAGE = (unset),
  16. download-from-binary-cache.pl: LC_ALL = (unset),
  17. download-from-binary-cache.pl: LANG = "en_US.UTF-8"
  18. [...]
  19. fetching path ‘/nix/store/6mk1s81va81dl4jfbhww86cwkl4gyf4j-stdenv’...
  20. perl: warning: Setting locale failed.
  21. perl: warning: Please check that your locale settings:
  22. LANGUAGE = (unset),
  23. LC_ALL = (unset),
  24. LANG = "en_US.UTF-8"
  25. are supported and installed on your system.
  26. perl: warning: Falling back to the standard locale ("C").
  27. *** Downloading https://cache.nixos.org/nar/0aznfg1g17a8jdzvnp3pqszs9rq2wiwf2rcgczyg5b3k6d0iricl.nar.xz’ to ‘/nix/store/6mk1s81va81dl4jfbhww86cwkl4gyf4j-stdenv’...
  28. % Total % Received % Xferd Average Speed Time Time Time Current
  29. Dload Upload Total Spent Left Speed
  30. 100 8324 100 8324 0 0 6353 0 0:00:01 0:00:01 --:--:-- 6373
  31. [nix-shell:~]$

检查GCC版本:

  1. [nix-shell:~]$ gcc -v
  2. Using built-in specs.
  3. COLLECT_GCC=/nix/store/dyj2k6ch35r1ips4vr97md2i0yvl4r5c-gcc-5.4.0/bin/gcc
  4. COLLECT_LTO_WRAPPER=/nix/store/dyj2k6ch35r1ips4vr97md2i0yvl4r5c-gcc-5.4.0/libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/lto-wrapper
  5. Target: x86_64-unknown-linux-gnu
  6. Configured with:
  7. Thread model: posix
  8. gcc version 5.4.0 (GCC)

现在,继续并测试代码。完成后,输入 exit 返回到控制台。

  1. [nix-shell:~]$ exit
  2. exit

一旦你从 nix-shell 中退出,你就不能使用 GCC。

这是另一个例子。

  1. $ nix-shell -p hello

这会构建或下载 GNU Hello 和它的依赖关系,然后将其放入 hello 命令所在的 Bash shell 中,所有这些都不会影响你的正常环境:

  1. [nix-shell:~]$ hello
  2. Hello, world!

输入 exit 返回到控制台。

  1. [nix-shell:~]$ exit

现在测试你的 hello 程序是否可用。

  1. $ hello
  2. hello: command not found

有关 Nix 包管理器的更多详细信息,请参阅以下指南。

希望本篇对你有帮助!还会有更好的东西。敬请关注!!

干杯!


via: https://www.ostechnix.com/how-to-test-a-package-without-installing-it-in-linux/

作者:SK 选题:lujun9972 译者:geekpi 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出



最新评论

从 2025.1.15 起,不再提供评论功能
LCTT 译者
geekpi 💎💎💎💎
共计翻译: 2095.5 篇 | 共计贡献: 3750
贡献时间:2013-10-25 -> 2024-01-31
访问我的 LCTT 主页 | 在 GitHub 上关注我


返回顶部

分享到微信

打开微信,点击顶部的“╋”,
使用“扫一扫”将网页分享至微信。