欢迎访问生活随笔!

生活随笔

您现在的位置是:首页 > 形式科学 > 操作系统 > Linux

Linux

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

发布时间:2022-06-09Linux 系统管理员
今天,我将向你展示如何在 Linux 中使用 Nix 包管理器来实现。Nix 包管理器的一个显著特性是它允许用户测试软件包而无需先安装它们。当你想要临时使用特定的程序时,这会很有帮助。

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

 

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

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

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

  1. $ nix-shell -p gcc
  2.  

该命令会构建或下载 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. [...]
  20.  
  21. fetching path ‘/nix/store/6mk1s81va81dl4jfbhww86cwkl4gyf4j-stdenv’...
  22. perl: warning: Setting locale failed.
  23. perl: warning: Please check that your locale settings:
  24. LANGUAGE = (unset),
  25. LC_ALL = (unset),
  26. LANG = "en_US.UTF-8"
  27. are supported and installed on your system.
  28. perl: warning: Falling back to the standard locale ("C").
  29.  
  30. *** Downloading ‘https://cache.nixos.org/nar/0aznfg1g17a8jdzvnp3pqszs9rq2wiwf2rcgczyg5b3k6d0iricl.nar.xz’ to ‘/nix/store/6mk1s81va81dl4jfbhww86cwkl4gyf4j-stdenv’...
  31. % Total % Received % Xferd Average Speed Time Time Time Current
  32. Dload Upload Total Spent Left Speed
  33. 100 8324 100 8324 0 0 6353 0 0:00:01 0:00:01 --:--:-- 6373
  34.  
  35. [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)
  9.  

现在,继续并测试代码。完成后,输入 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 包管理器的更多详细信息,请参阅以下指南。