Brew Virtualbox

Posted on  by admin
I’m fairly new on using MacOS. I’ve been struggling finding shortcuts and keys that I was very comfortable with in Windows. I friend of mine helped me with tips and also mentioned to install HomeBrew in order to install VirtualBox. Here’s a short post on how to do it.
  1. Brew Install Virtualbox
  2. Brew Virtualbox
  3. Brew Cask Virtualbox
  4. Brew Uninstall Virtualbox
  5. Brew Virtualbox Extension Pack
First you need to install Xcode. Xcode is a MacOS development framework application.
$:~ user$ xcode-select –install
xcode-select: note: install requested for command line developer tools

Homebrew’s package index. Name: Oracle VirtualBox Free and open-source hosted hypervisor for x86 virtualization. VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only is VirtualBox an extremely feature rich, high performance product for enterprise customers, it is also the only professional solution that is freely.

Then, you need to install HomeBrew. This version of HomeBrew doesn’t require to install Cask separately.
$:~ user$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
/usr/local/bin/brew
/usr/local/share/man/man1/brew.1
/usr/local/etc/bash_completion.d/brew
> Homebrew is run entirely by unpaid volunteers. Please consider donating:
> Tapping homebrew/core
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…
remote: Counting objects: 100% (4894/4894), done.
remote: Compressing objects: 100% (4697/4697), done.
remote: Total 4894 (delta 52), reused 324 (delta 6), pack-reused 0
Receiving objects: 100% (4894/4894), 4.00 MiB 372.00 KiB/s, done.
Tapped 2 commands and 4680 formulae (4,936 files, 12.4MB).
> Installation successful!
> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
> Homebrew is run entirely by unpaid volunteers. Please consider donating:
> Next steps:
– Further documentation:
As I previously mentioned, Cask is already included in the HomeBrew installation.
Now, lest try to use HomeBrew to search for the VirtualBox package.
> Casks
homebrew/cask-versions/virtualbox-extension-pack-beta
homebrew/cask/virtualbox-extension-pack
> Tapping homebrew/cask
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask’…
remote: Counting objects: 100% (4195/4195), done.

Brew Install Virtualbox

remote: Compressing objects: 100% (4185/4185), done.
remote: Total 4195 (delta 26), reused 915 (delta 7), pack-reused 0
Receiving objects: 100% (4195/4195), 1.33 MiB 241.00 KiB/s, done.
Tapped 1 command and 4096 casks (4,205 files, 4.2MB).
https://www.virtualbox.org/
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/virtualbox.rb
Oracle VirtualBox
VirtualBox.pkg (Pkg)
To install and/or use virtualbox you may need to enable their kernel extension in
System Preferences Security & Privacy General
For more information refer to vendor documentation or the Apple Technical Note:
https://developer.apple.com/library/content/technotes/tn2459/_index.html
$:~ user$ brew cask install virtualbox
To install and/or use virtualbox you may need to enable their kernel extension in
System Preferences Security & Privacy General
For more information refer to vendor documentation or the Apple Technical Note:
https://developer.apple.com/library/content/technotes/tn2459/_index.html
> Satisfying dependencies
> Downloading https://download.virtualbox.org/virtualbox/6.0.0/VirtualBox-6.0.
######################################################################## 100.0%
> Verifying SHA-256 checksum for Cask ‘virtualbox’.
> Running installer for virtualbox; your password may be necessary.
> Package installers may write to any location; options such as –appdir are i
installer: Package name is Oracle VM VirtualBox
installer: The install failed (The Installer encountered an error that caused the installation to fail. Contact the software manufacturer for assistance.)
> Purging files for version 6.0.0,127566 of Cask virtualbox

Brew Virtualbox

Error: Failure while executing; `/usr/bin/sudo -E — env LOGNAME=user USER=user USERNAME=user /usr/sbin/installer -pkg /usr/local/Caskroom/virtualbox/6.0.0,127566/VirtualBox.pkg -target /` exited with 1. Here’s the output:
installer: Installing at base path /
installer: The install failed (The Installer encountered an error that caused the installation to fail. Contact the software manufacturer for assistance.)
Follow the instructions here:
https://github.com/Homebrew/homebrew-cask#reporting-bugs
/usr/local/Homebrew/Library/Homebrew/system_command.rb:107:in `assert_success’
/usr/local/Homebrew/Library/Homebrew/system_command.rb:50:in `run!’
/usr/local/Homebrew/Library/Homebrew/system_command.rb:27:in `run’
/usr/local/Homebrew/Library/Homebrew/system_command.rb:31:in `run!’
Brew virtualbox failed
/usr/local/Homebrew/Library/Homebrew/cask/artifact/pkg.rb:59:in `block in run_installer’
/usr/local/Homebrew/Library/Homebrew/cask/artifact/pkg.rb:65:in `with_choices_file’
/usr/local/Homebrew/Library/Homebrew/cask/artifact/pkg.rb:52:in `run_installer’
/usr/local/Homebrew/Library/Homebrew/cask/artifact/pkg.rb:32:in `install_phase’
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:209:in `block in install_artifacts’
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/set.rb:674:in `each’
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/set.rb:674:in `each’
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:200:in `install_artifacts’
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:95:in `install’
/usr/local/Homebrew/Library/Homebrew/cask/cmd/install.rb:21:in `block in run’
/usr/local/Homebrew/Library/Homebrew/cask/cmd/install.rb:14:in `each’
/usr/local/Homebrew/Library/Homebrew/cask/cmd/install.rb:14:in `run’
/usr/local/Homebrew/Library/Homebrew/cask/cmd/abstract_command.rb:34:in `run’
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:89:in `run_command’
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:155:in `run’
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:120:in `run’
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:7:in `cask’
/usr/local/Homebrew/Library/Homebrew/brew.rb:88:in `’
As you can see, my installation failed. This is due to a new MacOS Sierra feature that prevents to load external libraries. I had to follow the instructions in below note:
Now that I have approved the extension let’s execute the install again.
$:~ user$ brew cask install –force virtualbox
To install and/or use virtualbox you may need to enable their kernel extension in
System Preferences Security & Privacy General
For more information refer to vendor documentation or the Apple Technical Note:
https://developer.apple.com/library/content/technotes/tn2459/_index.html
> Satisfying dependencies
> Downloading https://download.virtualbox.org/virtualbox/6.0.0/VirtualBox-6.0.
Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/c68cfddc9133da5c221557cd77b23f34e0b513dc380e6b010dc36b3d0eb2df45–VirtualBox-6.0.0-127566-OSX.dmg
> Verifying SHA-256 checksum for Cask ‘virtualbox’.
> Running installer for virtualbox; your password may be necessary.
> Package installers may write to any location; options such as –appdir are i
installer: Installing at base path /
virtualbox was successfully installed!
Now, just use spotlight search to find the VirtualBox application.
Hope this helps.

What is Docker?

Docker is the next step on long IT containerization way. What does it mean? Years ago, you could run each application/process in particular container, that application couldn’t go outside the container which it was run. It was very safe but difficult to manage and not sharable. So you couldn’t easy share your container to other machine or to other developers to reuse for example by open source community.

So, that solution was a little bit complicated and worked only on Linux. Today we have Docker, which allows you to run containers on all operation systems. What is important, this tool is not only modern but also easy to manage and easy to share to others developers.
[toc]

Other ways to install it

In this post, I want to show you how to install Docker by using brew which installation process I wrote last time. For me, it’s the easiest and safest way. But there are a few other possibilities to install it on Mac OS.

Docker.com – first method

First what you have to do is to go to Docker website and just download and run the .dmg file.

This is probably the easiest way, but unfortunately not the best. Using native install method you don’t have to install VirtualBox to run Linux, but sharing files between your Mac OS and systems in containers are really slowly. I can recommend that solution only if you want to test something or your project doesn’t use a framework with a lot of files.

Docker Toolbox – second method

It’s an app provided by Docker Company for Mac OS and Windows. The special feature in this toolbox is the requirement for VirtualBox, which will be a supervisor to run Linux. So, Docker is available as another machine in Docker environment. This toolbox contains also docker-compose (more below) and Kinematic, which allow you to manage your container by using GUI than a command line.

Install

I guess you have installed brew if not just follow this page and do everything that I’ve described.

If you are ready, open your terminal and type something like this:

If you have done it that you’ve received notice that docker-machine-driver-xhyve has to run as root, so you have to execute that commands:

Both commands will ask you for a password. Don’t worry to type it in a command line.

If everything goes ok then you can create your first docker machine, just type this command:

This command, as you suppose, creates a docker machine, using the xhyve driver.
--xhyve-experimental-nfs-share – this flag allows you to share each file in your /Users/ folder between Mac OS and Linux run on Docker.

Because you can have a lot docker machine, you can type this command in your terminal:

It registers a few variables, which allow you to use default docker machine without typing “default” each time.

Useful tools

Brew Cask Virtualbox

Probably, you’ve noticed that with docker you installed also docker-machine and docker-compose. These tools are not required but they are the strength of docker.

docker-machine

This tool allows you to prepare a lot of docker machines on your Mac OS, so you can have a lot of containers on many Linux distributions. You can dump all available commands just by typing docker-machine --help but most likely you will use three of them:

I guess I don’t have to describe what exactly this commands do. It’s so obvious. One thing you need to know, if something goes wrong, just try to restart your docker machine.

docker-compose

The main goal of docker: you can write like this “one process = one container”, but each app requires a lot process it could be a PHP, HTTP server, some database etc. Of course, you can run containers for each process manually, which is not a big deal with 3 containers, but trust me it escalates very fast, so you need an easy tool to manage your container and to manage the dependencies because one container can require access to another container. For example, PHP app needs information from a database, but it doesn’t need access to HTTP server. Of course, and HTTP server requires access to PHP.

To work with docker-compose you need to create an YAML file called docker-composer.yml where you describe which container you want to create and how they are linked between each other.

That file can look like this:

As you can see, you are creating two containers, first, contains MySQL database and second one – a WordPress instance. This example is flattened, in normal case you should split WordPress instance to three another containers: PHP, HTTP server and one for WordPress files.

There is also created one volume, which contains files of MySQL database. This solution prevents loosing data when you turn off your Mac, or just reset docker-machine or this particular container.

If you want to read something more about parameters available in docker-compose file, you can just go to docker documentation.

docker-compose, as well as other tools, provides a lot of commands available from a terminal, the number one is:

This command runs all containers defined in your docker-compose file. If it is needed – rebuild and remove old unused containers.

How to use

Everything that you need is in the section above. You can manage of course each particular container directly from command line using command docker. But it’s just wasting a time.

Brew Uninstall Virtualbox

Access by domain

Probably you want to access to your container by your web browser using some domains. You need to know what is IP of your docker machine and you can check it using command line just typing this:

You see IP and then use that IP in your /etc/hosts file.

Potential problems

Because you are trying to run Linux environment on Mac OS you can some across a lot strange problems if you want to use it in common work. Fortunately, you just need to follow some rules to enjoy work with docker.

Sharing files

If you installed a docker as described above you can share only files from your /Users/ folder. You can debug what is sharable directly on your docker machine, which can receive access directly from command line, like this:

Now, you are logged on your Linux and can browse to / and check is there /Users/ folder which contains files from your Mac OS. If you don’t see your files, just try to reinstall Docker and xhyve.

Speed of I/O process

Because docker needs transfer files between your Mac OS and Linux using the NFS it’s always more slowly then operation directly on your disk. So, if you want to boost up your application you have to remember to share only needed files. if you are backend develop you don’t share frontend javascript libraries, just put in into inside container.

Don’t forget to ignore cache and logs files!

Brew Virtualbox Extension Pack

Access via domain/IP

Restarting Mac OS or docker-machine sometimes restarts also IP of the docker machine. If you can’t connect to your docker just check the current IP using this command:

If it doesn’t work, you have to update domains in your /etc/hosts file.