NixOS 系列 #2：如何在虚拟机上安装 NixOS？
NixOS
![](/data/attachment/album/202303/14/154007dt8ucpf8co9o9otf.jpg)


如果你可以在任何 Linux 发行版上使用 Nix 包管理器，为什么还要安装 NixOS？


在使用 NixOS 几天之前，我经常想知道同样的事情。


当我意识到这些好处后，我就写了这篇文章来帮助你了解 [为什么你要考虑使用 NixOS](/article-15606-1.html)。如果你已经阅读了本系列的第一篇文章，那么你已经知道自己想要什么了。


那么，如何开始呢？考虑到它对许多人来说可能是一种新体验，你应该用它替换日常使用的系统还是将其安装为虚拟机？


我建议在你想要将其替换为你的主要操作系统之前在虚拟机上使用 NixOS。这适用于你想尝试的任何新事物，特别是 [先进的 Linux 发行版](https://itsfoss.com/advanced-linux-distros/)，例如 NixOS。


### 使用 VirtualBox 在 VM 中安装 NixOS


在本教程中，我将使用 VirtualBox。


如果你使用的是 Ubuntu 并且不关心是否拥有最新版本，那么可以使用一个命令安装 VirtualBox：



```
sudo apt install virtualbox

```

想要安装最新版本？你可以参考下面的指南：



> 
> **[如何在 Ubuntu 上安装 VirtualBox（初学者教程）](https://itsfoss.com/install-virtualbox-ubuntu/)**
> 
> 
> 


如果你使用 Ubuntu 以外的任何发行版，你可以 [按照其官方下载页面的下载说明进行操作](https://www.virtualbox.org/wiki/Linux_Downloads)。


成功安装 VirtualBox 后，让我们从第一步开始。


#### 步骤 1：获 取NixOS 的 ISO 镜像


你需要前往 NixOS [官方下载页面](https://nixos.org/download.html)。


在 “NixOS: the Linux distribution” 部分，你会找到带有 GNOME 和 KDE 桌面的 ISO。


当然，也有最小化 ISO，但我建议使用两者之一（GNOME 和 KDE）：


![下载 NixOS ISO 文件](/data/attachment/album/202303/14/154018embsmm7pbb0oe70w.png)


对于本教程，我将使用 GNOME。


请记住，你可以选择 GNOME 和 KDE 两种<ruby> 立付桌面环境 <rt>  Live Desktop </rt></ruby>。


而在安装过程中，你可以选择自己喜欢的桌面环境，包括 **Xfce、Pantheon、Cinnamon、MATE** 等等！


#### 步骤 2：在 VirtualBox 中创建虚拟机


打开 VirtualBox 并单击 “<ruby> 新建 <rt>  New </rt></ruby>” 按钮添加新的虚拟机：


![截图显示了如何点击新建按钮来添加新的虚拟机](/data/attachment/album/202303/14/154018pg1bg82ub771gklb.png)


它将打开一个提示，要求你添加有关要添加的虚拟机的信息。


你可以先命名虚拟机：


* 为你的虚拟机命名，以便你可以识别它是 NixOS 系统。所以我将其命名为 “NixOS”。
* 选择你刚刚下载的 ISO 镜像。
* 选择 “Linux” ISO 类型。
* 并在版本选择 “<ruby> 其它 Linux（64 位） <rt>  Other Linux (64-bit) </rt></ruby>”。


![](/data/attachment/album/202303/14/154019m9z4395wr7o4xuwo.png)


选择所有内容后，单击 “<ruby> 下一步 <rt>  Next </rt></ruby>” 按钮。


接下来，系统会要求你选择基本内存（RAM）、要分配给此虚拟机的处理器以及存储空间。


虽然 NixOS 没有提到官方要求，但我建议你为此安装至少拥有 **4GB RAM**、**2-4 个处理器内核**和 **30GB 空间**：


![选择 NixOS 虚拟机的硬件](/data/attachment/album/202303/14/154020yc4ko954c54kka9p.png)


最后，它会显示你为此虚拟机所做选择的摘要：


![NixOS 虚拟机 安装摘要](/data/attachment/album/202303/14/154020faatpyn2eraaouh8.png)


如果一切正常，请单击 “<ruby> 完成 <rt>  Finish </rt></ruby>” 按钮，它将为你创建一个 NixOS 虚拟机。


#### 步骤 3：安装 NixOS


创建完虚拟机后，你为 NixOS 虚拟机指定的名称应该显示在 VirtualBox 的虚拟机列表中。


选择 “NixOS” 虚拟机并单击“开始”按钮：


![开始 NixOS 虚拟机](/data/attachment/album/202303/14/154020cv68gox88wgz8o6o.png)


它将启动 NixOS <ruby> 立付桌面环境 <rt>  Live Desktop </rt></ruby>，以便你可以试用 Linux 发行版。


##### 选择安装语言


启动进入 NixOS 后，安装程序将启动并要求你设置安装程序的首选语言：


![选择安装时的首选语言](/data/attachment/album/202303/14/154021vmrh8qqbbpi7h7ix.png)


##### 选择地区和时区


接下来，选择你所在的地区和区域。如果你不知道这一点，你可以从地图上选择你的国家，它会为你设置。


选择区域和区域后，它还会选择系统的首选语言、数字和日期区域设置。


当然，你可以根据需要进行更改，但对于大多数用户而言，选定的选项就可以正常工作：


![选择地区和时区](/data/attachment/album/202303/14/154022tyc2n6xn26rhj16g.png)


##### 选择键盘布局


接下来，你将必须设置键盘布局。对于大多数用户来说，默认设置的 “English (US)” 应该可以正常工作。


如果你要进行其他操作，则可以在继续之前测试你的键盘配置。


![选择键盘格式](/data/attachment/album/202303/14/154022ifatn5tht1nca1a8.png)


之后，系统会要求你创建一个用户并为该用户设置密码。


你可以选择为虚拟机保留一个强密码或任何随机密码。


![创建用户](/data/attachment/album/202303/14/154023px2xx2q72zn22x1o.png)


##### 选择你喜欢的桌面环境


使用 NixOS，你可以选择以下桌面环境：


* GNOME
* KDE（定制的最佳选择）
* Xfce
* Pantheon（ElementaryOS 附带的桌面环境）
* Cinnamon
* Enlightenment
* LXQt


![选择桌面环境](/data/attachment/album/202303/14/154023vjaeddamdazk9evo.png)


##### 在 NixOS 上使用非自由软件


NixOS 遵循与 Fedora 类似的方法，你必须选择是否需要非自由软件。


我建议你启用非自由包：


![启用非自由软件包](/data/attachment/album/202303/14/154024py154o8qkxapekrg.png)


##### 分区部分


由于这是一个虚拟机指南，我建议你使用自动对磁盘进行分区的 “<ruby> 擦除磁盘 <rt>  Erase disk </rt></ruby>” 选项！


![自动分区](/data/attachment/album/202303/14/154024r927b834b6kx8988.png)


完成后，它将为你提供你所做选择的摘要：


![安装选择摘要](/data/attachment/album/202303/14/154024wpv622fn4wp9zkef.png)


如果一切正常，请单击 “<ruby> 安装 <rt>  Install </rt></ruby>” 按钮，它将开始安装。


##### 不要重启而是关闭虚拟机


安装完成后，你可以选择重新启动虚拟机。


如果你这样做，**它将再次加载安装程序**！


要解决此问题，你必须更改引导顺序。


为此，请在安装完成后关闭虚拟机。


要关闭虚拟机，请从“<ruby> 文件 <rt>  File </rt></ruby>”菜单中选择 “<ruby> 关闭 <rt>  Close </rt></ruby>” 选项，然后选择 “<ruby> 关闭虚拟机电源 <rt>  Power off the machine </rt></ruby>” 选项：


![](/data/attachment/album/202303/14/154025fn8aq9l55ci4gl46.png)


##### 更改 VirtualBox 中的启动顺序


要更改 NixOS 虚拟机 中的启动顺序，请打开该虚拟机的设置：


![](/data/attachment/album/202303/14/154025elgevguuubmi4be7.png)


在设置中，选择 “<ruby> 系统 <rt>  System </rt></ruby>”，你将找到启动顺序。


在这里，选择 “<ruby> 硬盘 <rt>  Hard Disk </rt></ruby>” 并使用选项旁边的**向上箭头**图标并将其设为启动的第一个选项：


![改变启动顺序](/data/attachment/album/202303/14/154025sd6kk24ombkudboh.gif)


按下 “<ruby> 确定 <rt>  OK </rt></ruby>”，它将保存你所做的更改。


**或者**，你可以移除我们添加的用于启动安装的光盘（ISO 镜像）。


#### 步骤 4：从 NixOS 安装启动


现在，启动你的 NixOS 虚拟机，你将看到一个 GRUB 屏幕：


![NixOS grub](/data/attachment/album/202303/14/154026k2e2pzuw302inky2.png)


选择默认选项，它将带你进入带有 GNOME 桌面的全新 NixOS 安装。


![运行 NixOS](/data/attachment/album/202303/14/154026z3oktc7mzma0a4kn.png)


就是这些了！**请继续探索 NixOS！**


### 总结


这是关于如何在 VirtualBox 上安装 NixOS 的快速指南。


对于 NixOS 教程系列的下一部分，我将分享有关**安装和删除包**的建议。


? *敬请期待本系列的下一部分。在那之前，请随时分享你对 NixOS 的看法或在遵循指南时遇到任何问题！*




---


via: <https://itsfoss.com/install-nixos-vm/>


作者：[Sagar Sharma](https://itsfoss.com/author/sagar/) 选题：[lkxed](https://github.com/lkxed/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
# Install NixOS on a Virtual Machine

Want to try NixOS? Get started by installing it on a virtual machine.

If you can use the Nix package manager on any Linux distro, why should you install the NixOS?

I often wondered about the same before using NixOS for a few days.

Once I realized the benefits, I wrote about it to help you know [why you might consider using NixOS](https://itsfoss.com/why-use-nixos/). If you have read the first article of the series, you already know what you want.

So, how to get started with it? Considering it can be a new experience for many, should you replace your daily driver with it or install it as a virtual machine?

I recommend using NixOS on a VM before you want to replace it as your primary operating system. This holds for anything new that you want to try, but specifically for [advanced Linux distributions](https://itsfoss.com/advanced-linux-distros/) like NixOS.

## Install NixOS in the VM Using VirtualBox

In this tutorial, I will be using VirtualBox.

And if you are using Ubuntu and don't care about having the latest version, VirtualBox can be installed using a single command:

`sudo apt install virtualbox`


Want to install the latest version? You can refer to the given guide:

[How to Install VirtualBox on Ubuntu [Beginner’s Tutorial]This beginner’s tutorial explains various ways to install VirtualBox on Ubuntu and other Debian-based Linux distributions. Oracle’s free and open-source offering VirtualBox is an excellent virtualization tool, especially for desktop operating systems. I prefer using it over VMWare Workstation i…](https://itsfoss.com/install-virtualbox-ubuntu/)![](https://itsfoss.com/content/images/wordpress/2019/02/virtualbox-ubuntu.png)


![](https://itsfoss.com/content/images/wordpress/2019/02/virtualbox-ubuntu.png)

And if you are using anything besides Ubuntu, you can[ follow the download instructions from its official downloads page.](https://www.virtualbox.org/wiki/Linux_Downloads)

Once you have successfully installed VirtualBox, let us start with the first step.

### Step 1: Get the ISO image of NixOS

You need to head to NixOS [official download page](https://nixos.org/download.html).

And under the `NixOS: the Linux distribution`

section, you will find ISO with GNOME and KDE desktops.

Sure, there is a minimal ISO, too, but I would recommend going with either of the two (GNOME and KDE):

![Download NixOS ISO file](https://itsfoss.com/content/images/2023/02/Download-NixOS-ISO-file.png)

For the sake of this tutorial, I will be using GNOME.

Remember, you are given GNOME and KDE options for the live desktop!

And during installation, you get the option to choose your favorite desktop environment, including **Xfce, Pantheon, Cinnamon, MATE**, and more!

### Step 2: Create a virtual in VirtualBox

Open VirtualBox and click on the `New`

button to add a new virtual machine:

![screenshot that shows you how to click on new button to add new virtual machine](https://itsfoss.com/content/images/2023/02/click-on-new-to-add-new-virtual-machine.png)

And it will open a prompt asking you to add information about the VM you want to add.

You can start by naming your VM:

**Name your VM so that you can identify it is a NixOS install. So I named it**`NixOS`

.**Choose the ISO image that you've downloaded recently.****Select**`Linux`

as a type of ISO.**And choose**`Other Linux (64-bit)`

for version.

![](https://itsfoss.com/content/images/2023/02/Add-NixOS-ISO-to-VirtualBox.png)

Once you select everything, click on the `Next`

button.

Next, you will be asked to choose the Base memory (RAM), processors you want to allocate to this VM, and storage space for this install.

While NixOS mentions no official requirements, I recommend you to have at least **4 gigs of RAM**, **2-4 processor cores**, and **30 GB of space** for this install:

![select hardware for NixOS VM](https://itsfoss.com/content/images/2023/02/select-hardware-for-NixOS-VM-1.png)

And in the end, it will show you the summary of the choices you made for this VM:

![summary of NixOS VM install](https://itsfoss.com/content/images/2023/02/summery-of-NixOS-VM-install.png)

If everything seems fine, click on the `Finish`

button and it will create a NixOS virtual machine for you.

**Suggested Read 📖**

[How to Install Linux Inside Windows Using VirtualBoxUsing Linux in a virtual machine allows you to try Linux within Windows. This step-by-step guide shows you how to install Linux inside Windows using VirtualBox.](https://itsfoss.com/install-linux-in-virtualbox/)![](https://itsfoss.com/content/images/wordpress/2018/03/install-linux-inside-windows-featured.jpg)


![](https://itsfoss.com/content/images/wordpress/2018/03/install-linux-inside-windows-featured.jpg)

### Step 3: Installing NixOS

Once you are done creating the VM, the name you gave to your NixOS VM should start reflecting in the VirtualBox list of VMs.

Select the NixOS VM and click on the start button:

![start the NixOS VM](https://itsfoss.com/content/images/2023/02/start-the-NixOS-VM.png)

And it will start the NixOS live so you can try the Linux distro.

#### Select installer language

Once you boot into the NixOS, the installer will start and ask you to set the preferred language for the installer:

![choose preferred language for NixOS install](https://itsfoss.com/content/images/2023/02/1.-choose-the-language-of-NixOS-installer.png)

#### Choose region and timezone

Next, choose your region and zone. If you don't know this, you can select your country from the map, which will set things for you.

Once you select the region and zone, it will also select the preferred language, numbers, and date locale.

Sure, you can change if you want to, but for most users, the selected options will work just fine:

![choose the region and zone for NixOS](https://itsfoss.com/content/images/2023/02/2.-choose-the-region-and-zone-for-NixOS.png)

#### Select Keyboard layout

Next, you will have to set the keyboard layout. For most users, `English (US)`

with default setting should work fine.

If you are going with something else, you can test your keyboard configuration before proceeding.

![select Keyboard layout for NixOS](https://itsfoss.com/content/images/2023/02/3.-select-Keyboard-layout-for-NixOS.png)

After that, you are asked to create a user and set a password for that user.

You can choose to keep a strong password or just anything random for the VM.

![create a user for NixOS](https://itsfoss.com/content/images/2023/02/4.-create-user-and-set-password-for-NixOS.png)

#### Select your favorite Desktop Environment

With NixOS, you are given the following choices for the desktop environment:

- GNOME
- KDE (best choice for customization)
- Xfce
- Pantheon (a desktop environment that ships with ElementaryOS)
- Cinnamon
- Enlightenment
- LXQt

![choose desktop environment for NixOS](https://itsfoss.com/content/images/2023/02/5.-choose-desktop-environment-for-NixOS.png)

**Suggested Read 📖**

[KDE vs GNOME: What’s the Ultimate Linux Desktop Choice?Curious about the desktop environment to choose? We help you with KDE vs GNOME here.](https://itsfoss.com/kde-vs-gnome/)![](https://itsfoss.com/content/images/wordpress/2022/02/gnome-vs-kde.png)


![](https://itsfoss.com/content/images/wordpress/2022/02/gnome-vs-kde.png)

#### Use non-free software on NixOS

NixOS follows a similar approach to Fedora, where you have to choose whether you want the non-free software.

I would recommend you enable non-free packages:

![enable non-free package in NixOS](https://itsfoss.com/content/images/2023/02/6.-Allow-unfree-software.png)

#### The partitions part

As this is a VM guide, I will recommend you go with the `Erase disk`

option that should partition the disk automatically!

![automatic partition the disk for NixOS](https://itsfoss.com/content/images/2023/02/7.-select-erase-disk-option-while-installing-NixOS.png)

Once done, it will get you the summary of the choices you went with:

![summery of NixOS installation options in VM](https://itsfoss.com/content/images/2023/02/8.-summery-of-NixOS-installation-options-in-VM.png)

And if everything seems correct, click on the `Install`

button, and it will start the installation button.

#### Don't Reboot but turn off the VM

Once the installation is finished, you will be given the option to restart the VM.

And if you do so,** it will load the installer again**!

To solve this issue, you must make changes in the boot sequence.

And to do that, power off your VM once the installation is complete.

To power off the VM, select the `Close`

option from the **File menu** and select the `Power off the machine`

option:

![](https://itsfoss.com/content/images/2023/02/poweroff-VM.png)

#### Change the boot order in VirtualBox

To change the boot order in the NixOS VM, open the settings for that VM:

![](https://itsfoss.com/content/images/2023/02/open-settings-for-VM-in-VirtualBox.png)

In settings, select `System`

and you will find the boot order.

Here, select the `Hard Disk`

and use the **up arrow** icon next to the options and make it the first option to boot:

![change boot order in VirtualBox](https://itsfoss.com/content/images/2023/02/how-to-change-the-boot-order-in-VirtualBox.gif)

Press `OK`

and it will save the changes you made.

**Alternatively**, you can remove the optical disk (ISO image) that we added to start the installation.

### Step 4: Boot from NixOS install

Now, start your NixOS VM, and you will see a GRUB screen:

![NixOS grub screen](https://itsfoss.com/content/images/2023/02/NixOS-grub-screen.png)

Select the default option, and it will get you into the fresh install of NixOS with the GNOME desktop.

![running NixOS in VM](https://itsfoss.com/content/images/2023/02/running-NixOS-in-VM.png)

That's it! **Go on exploring NixOS!**

## Wrapping Up

This was a quick guide on how you can install NixOS on VirtualBox.

For the next part of this series, I shall share pointers on [installing and removing packages in NixOS](https://itsfoss.com/nixos-package-management/).

[NixOS Series #3: Install and Remove Packages in NixOSIt can be a bit different when installing and removing packages in NixOS. Here, we explain it to make things easy.](https://itsfoss.com/nixos-package-management/)![](https://itsfoss.com/content/images/2023/03/install-and-remove-packages-in-nixos.png)


![](https://itsfoss.com/content/images/2023/03/install-and-remove-packages-in-nixos.png)

💬 *Stay tuned for the next part of the series. Until then, feel free to share your thoughts on NixOS and if you face any issues following the guide!*