何らかの理由で、Linuxシステムにインストールする前にパッケージをテストすることをお勧めします。もしそうなら、あなたは幸運です!今日は、 Nixを使用してLinuxでそれを行う方法を紹介します。 パッケージマネージャー。 Nixパッケージマネージャーの注目すべき機能の1つは、ユーザーが最初にパッケージをインストールしなくてもパッケージをテストできることです。これは、特定のアプリケーションを一時的に使用する場合に役立ちます。
Linuxにインストールせずにパッケージをテストする
最初にNixパッケージマネージャーをインストールしたことを確認してください。まだインストールしていない場合は、次のガイドを参照してください。
- Nix –LinuxおよびUnix用の強力なパッケージマネージャー
たとえば、C++コードをテストするとします。 GCCをインストールする必要はありません。次のコマンドを実行するだけです:
$ nix-shell -p gcc
このコマンドは、gccパッケージとその依存関係をビルドまたはダウンロードしてから、 gccがあるBashシェルにドロップします。 コマンドが存在し、通常の環境に影響を与えることはありません。
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)
次に、コードをテストします。完了したら、 exitと入力します コンソールに戻ります。
[nix-shell:~]$ exit exit
nix-shellを終了すると、GCCを使用できなくなります。
別の例を示します。
$ nix-shell -p hello
これにより、GNU Helloとその依存関係が構築またはダウンロードされ、 helloが存在するBashシェルに移動します。 コマンドが存在し、通常の環境に影響を与えることはありません:
[nix-shell:~]$ hello Hello, world!
exitと入力して、コンソールに戻ります。
[nix-shell:~]$ exit
次に、helloプログラムが利用可能かどうかをテストします。
$ hello hello: command not found
Nixパッケージマネージャーの詳細については、次のガイドを参照してください。
- Nixパッケージマネージャーの使用を開始する