如何在Linux中不安裝軟件測試一個軟件包
出于某種原因,你可能需要在將軟件包安裝到你的 Linux 系統(tǒng)之前對其進行測試。如果是這樣,你很幸運!今天,我將向你展示如何在 Linux 中使用 Nix 包管理器來實現(xiàn)。Nix 包管理器的一個顯著特性是它允許用戶測試軟件包而無需先安裝它們。當你想要臨時使用特定的程序時,這會很有幫助。
測試一個軟件包而不在 Linux 中安裝它
確保你先安裝了 Nix 包管理器。如果尚未安裝,請參閱以下指南。
例如,假設你想測試你的 C++ 代碼。你不必安裝 GCC。只需運行以下命令:
$ nix-shell -p gcc
該命令會構建或下載 gcc 軟件包及其依賴項,然后將其放入一個存在 gcc
命令的 Bash shell 中,所有這些都不會影響正常環(huán)境。
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)
現(xiàn)在,繼續(xù)并測試代碼。完成后,輸入 exit
返回到控制臺。
[nix-shell:~]$ exit
exit
一旦你從 nix-shell 中退出,你就不能使用 GCC。
這是另一個例子。
$ nix-shell -p hello
這會構建或下載 GNU Hello 和它的依賴關系,然后將其放入 hello
命令所在的 Bash shell 中,所有這些都不會影響你的正常環(huán)境:
[nix-shell:~]$ hello
Hello, world!
輸入 exit
返回到控制臺。
[nix-shell:~]$ exit
現(xiàn)在測試你的 hello
程序是否可用。
$ hello
hello: command not found
有關 Nix 包管理器的更多詳細信息,請參閱以下指南。