如何在不将其安装在Linux中的情况下测试包

时间:2020-03-21 11:45:02  来源:igfitidea点击:

出于某种原因,我们可能希望在Linux系统中安装之前测试包。
如果是这样,你很幸运!今天,将介绍如何使用nix包管理器在Linux中进行操作。
nix包管理器的一个值得注意的功能是它允许用户测试包而无需首先安装它们。
当我们临时使用特定应用程序时,这可能会有所帮助。

在没有安装Linux的情况下测试包

确保首先已安装NIX包管理器。

例如,让我们说要测试C++代码。
我们不必安装GCC。
只需运行以下命令:

$nix-shell -p gcc

此命令构建或者下载GCC软件包及其依赖项,然后将Bash shell丢弃到存在的Bash shell中,所有内容都不会影响正常环境。

LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
download-using-manifests.pl: perl: warning: Setting locale failed.
download-using-manifests.pl: perl: warning: Please check that your locale settings:
download-using-manifests.pl: LANGUAGE = (unset),
download-using-manifests.pl: LC_ALL = (unset),
download-using-manifests.pl: LANG = "en_US.UTF-8"
download-using-manifests.pl: are supported and installed on your system.
download-using-manifests.pl: perl: warning: Falling back to the standard locale ("C").
download-from-binary-cache.pl: perl: warning: Setting locale failed.
download-from-binary-cache.pl: perl: warning: Please check that your locale settings:
download-from-binary-cache.pl: LANGUAGE = (unset),
download-from-binary-cache.pl: LC_ALL = (unset),
download-from-binary-cache.pl: LANG = "en_US.UTF-8"
[...]
fetching path ‘/nix/store/6mk1s81va81dl4jfbhww86cwkl4gyf4j-stdenv’...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
*** Downloading ‘https://cache.nixos.org/nar/0aznfg1g17a8jdzvnp3pqszs9rq2wiwf2rcgczyg5b3k6d0iricl.nar.xz’ to ‘/nix/store/6mk1s81va81dl4jfbhww86cwkl4gyf4j-stdenv’...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8324 100 8324 0 0 6353 0 0:00:01 0:00:01 --:--:-- 6373
[nix-shell:~]$

检查GCC版本:

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

现在,继续测试代码。
完成后,键入退出以返回到控制台。

[nix-shell:~]$exit
exit

退出nix-shell后,我们无法使用GCC。

这是另一个例子。

$nix-shell -p hello

这构建或者下载GNU Hello及其依赖项,然后将我们丢弃到存在Hello命令的Bash shell中,所有都不会影响正常环境:

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

类型退出返回到控制台。

[nix-shell:~]$exit

现在测试我们是否可以使用或者不可使用。

$hello 
hello: command not found