Offering great convenience and security, virtual machines are a popular staple for those who like to tinker and experiment on different operating systems. As personal computers become more and more capable, the market for virtual machines grew with it. Today, PCs can run several operating systems simultaneously.

The current generation of smartphones has become capable devices. Users can edit videos, play complex games at high resolutions, stream and watch 4K videos, and emulate software meant for computers. This begs the question—can you run a virtual machine on a smartphone?

Can Smartphones Run a Virtual Machine?

The short answer is Yes. In fact, every smartphone is running on a virtual machine of sorts. Currently, Android smartphones run through ART (Android Runtime). This allows the bytecodes from APK files to be translated into binary code, which a processor can read and execute. Ever since the implementation of ART, Android devices with two gigabytes of RAM (or more) could comfortably run a virtual machine.

It's been years since 2GB of RAM was a thing, and most modern smartphones launch with more. So, running a virtual machine on a smartphone is a lot easier now than ever.

What Apps Do I Need To Run a Virtual Machine on My Smartphone?

To run a virtual machine on your smartphone, you'll need to install two applications through Google Play.

Andronix is one of the easiest ways to run a virtual machine on your android smartphone. The app provides you with all the tools and instructions. It also provides you with copies of the code needed to install the operating system. Andronix is partially open-source, and they currently provide users with several popular Linux distributions for free.

Unless you're comfortable using only a command-line interface with your virtual machine, you'll need to install a third-party application for a GUI (graphical user interface). This is where VNC Viewer comes in. By specifying a local host and providing the correct password (that you determine), VNC Viewer and its RFB (Remote Frame Buffer) protocol will connect to your device and provide a graphical interface.

Related: How to Remotely Control Your PC With Your Android Phone

How to Run VM on a Smartphone

Once you've downloaded and installed both apps, have your phone charged and find a place with a strong Wi-Fi connection before you begin.

1. Open the Andronix App and Install Termux

Once you open the app, you'll immediately see all the free Linux distributions you can run on your phone. These distros include Ubuntu, Kali Linux, Debian, Arch Linux, Manjaro, Fedora, Void, and Alpine.

Navigate to the Termux installation page by touching the drop-down icon on the upper left side of your screen. Go to Settings, and swipe down to the end of the page. Select Run Termux Setup, then select Download. Once it's downloaded, select Allow Installation, and you're done.

2. Install Your Preferred Operating System

In Andronix, go back to the main menu and select the distro you want to use. Once selected, the app will indicate the difficulty of installing the specific distro and any complications you might face.

Select Proceed and install. Andronix will provide you with GUI options: Desktop Environment, Window Managers, and CLI Only.

If you purely want to use your smartphone and need a GUI, select Desktop Environment. Windows Managers will provide you with a GUI and a keyboard to navigate through the window. CLI Only will strictly use a terminal; only go for this option if you are confident with the distro.

After selecting your GUI, Andronix will provide you with desktop environment options. XFCE is an old lightweight Linux desktop environment; go for this option only if you want to. LXQT superseded LXDE. If you want the best performance out of the three options, go for LXQT.

Once you select your preferred desktop environment, a prompt will appear informing you that a command has been copied to your clipboard. Select Open Termux and paste the command.

The installation will start at this point. It will take a bit of time to install fully. Make sure to check your phone every once in a while because you will need to specify your location, language, time. When the installation is almost done, you will be asked to provide a password. Don't worry if you type on the keyboard and it doesn't seem to be typing—that's just how Linux operates.

Related: The Best Lean Linux Desktop Environment: LXDE vs. Xfce vs. MATE

3. Start the VNC Server

On the first startup, you will find an option on the resolution you want your server to use. Again, experiment and find what you like. The fourth option (HD-ready resolution) is always a good option.

4. View the Virtual Machine Through VNC Viewer

Open VNC Viewer and select the plus icon, which will open up a form. On the Address field, input localhost:1. You can input anything you want for the Name field. Press CREATE. You will receive a warning but can just press OK.

Screenshot_2022-01-03-22-58-18-10
Smartphone-running-ubuntu-on-VM

You will then be prompted to input the password you made earlier. Once you press CONTINUE, you will be in control of your virtual machine with a GUI. Enjoy!

How to Start VM and VNC Server

Open the Termux app and use the command ls to view the contents of your current directory.

        ls
    

Use the command ./ (dot slash) along with the .sh file colored in green and begins with the word Start. This will start the VM on your phone and assign you as user "root@localhost". You have successfully run your smartphone virtual machine. For example, the command below will start an Ubuntu virtual machine.

        ./start-ubuntu20.sh
    

To start the VNC server, you must use the command server start command.

        vncserver-start

Properly Close Your Server and VM

It is important that you properly close your server and VM to save battery and spare you from all the problems you might face if you don't close them properly.

When exiting your VNC viewer, make sure to shut it down just like a regular computer. After that, go to your terminal and use the command vncserver-stop, then type 1 or the number corresponding to the VNC server you want to close.

        vncserver-stop
    

To close the VM, all you have to do is use the command exit. To exit Termux, also use the exit command.

        exit
    

Based on the many queries on the internet about having a hard to opening a server, many people seem to forget to close the VNC server after the initial startup. To save you from all the complicated answers of the internet, you have to close the first VNC server opened during the initialization. You can do that by using the vncserver-stop command.

Can You Install a Virtual Machine on an iPhone?

IPhone_XS

Installing a virtual machine on an Apple product is possible. However, it may not be as straightforward as it is with Android. The best way to do it would be through UTM. UTM is an app you can use on an Apple device to run other operating systems such as Windows and various Linux distributions.

The great thing about UTM is that you don't need to jailbreak for iOS 11, 12, 13, and some variations of iOS 14. It is also an open-source app that you can personally check on GitHub. The app is reasonably easy to use, so long as you follow the user's guide.

The problem with UTM is that Apple won't allow you to install it as a "regular consumer." In fact, the app isn't listed on the App Store. The only way you can install UTM on your iPhone is if you provide a certificate that shows you are a developer testing an app on the device.

iPhone offers free and paid subscriptions to get a developer's certificate. This shouldn't be a problem if you don't mind paying the 99USD for a year subscription. But if you want to go the free route, you'll have to keep asking for new certificates every seven days.

To make the free developer certificates more convenient to use, you can install an app called AltStore. The AltStore is also where you can download and install UTM. Aside from being an alternative to the AppStore, this app will auto-sign your free developer certificate, so you won't have to ask for one manually every seven days.

The Future of VM on Smartphones

Running a virtual machine on a smartphone has always been a possibility. However, it was only a few years back when people could finally run a usable virtual machine. Today, running one or two watered-down operating systems is about the limits of what phones can do. However, as smartphone manufacturers keep improving upon their products, you can be sure that someday, smartphones will be capable of running full-fledged virtual operating systems with great stability.