Jason Thomas

I like to make stuff

November 29, 2016 @ 22:32

Getting Python + MongoDB to work on a FreeBSD VM

I recently needed to install FreeBSD on a virtual machine to help a colleague with a Python issue that I couldn't recreate on my Linux machine.

Learning a new operating system is hard, but I also didn't know how to use virtualbox at all. This is a pocket guide I'm putting together, mainly for future reference. To be fair FreeBSD is based on Unix so this was familiar (it's actually closer to Unix I believe.)

Here are the steps that worked getting this to work on my Linux laptop:

  1. Install virtualbox sudo apt-get install virtualbox

  2. Setup a virtual machine using this guide. Make sure to check the FreeBSD operating system from the dropdown menu. If you intend to install gnome and other programs, make your partition on the larger side to be sure (I made mine 35 gigabytes to be sure). The default is 1024 MB of RAM, but I needed to beef mine up to 3.5 GB, because the Pythonn project I needed to test was a RESTful API. So I used Opera and the Simple REST Client, rather than Firefox or Google Chrome, because Opera uses a lot less juice.

  3. Download a compatible FreeBSD disc image. Virtualbox on my machine only works in 32 bit, so download an i383 image from the FreeBSD website. Download the disc1.iso

  4. The first time you run the virtual machine after setting it up, you'll be prompted to selected a storage location. Select your downloaded disc image.

  5. Follow all steps to install FreeBSD, I thought it was pretty straight-forward.

  6. When that's done, exit the installer and power down the machine. Now in the menu for the virtual machine, remove the disc image from the virtual machine's settings. Or you could change the boot order to allow the virtual machine to load from the virtual harddrive.

  7. FreeBSD should load and ask you to login. I just logged in as root and did everything that way, since this is a throw-away machine. You should now be able to install gnome3 to use the virtual machine. (You can run Python from the terminal but I needed to run a web browser in this VM so I needed a desktop). Run this to install the requirements: pkg install gnome3 xorg

  8. I'm a big fan of Vim and I'll use Vim shortly, so I did: pkg install vim

  9. Now, go up/out to the root directory and you should see the etc folder. Do: vim /etc/rc.conf. Inside this file, you want to add:

dbus_enable="Yes"
zfs_enable="Yes"
hald_enable="Yes"
gdm_enable="Yes"
gnome_enable="Yes"
  1. Reboot your machine and it should load with a shiny GUI for you to use.

  2. I needed Git, Python and Virtualenv to do my work so I did this:

    pkg install python pkg install devel/py-virtualenv pkg install git

  3. If you want to avoid using a password to download git repos to your machine, and assuming you use BitBucket or Github etc, then you can follow this guide to create a new public/private ssh key pair. To copy the public key to your clip board, go to the virtualbox main screen and under settings > advanced make sure Shared Clipboard is set to bidirectional, so then you can copy them public key from the terminal using Vim, and place that key on the website.

  4. Inside your downloaded project, you can run your virtualenv the usual way with with *csh on the end:

    virtualenv venv source venv/bin/activate.csh

Otherwise you can use pip and run Python the same.

BTW I needed to use MongoDB and pymongo in my project, and this document got me out of trouble.

So that's mostly it fellow Linux users. My simple use case is pretty similar to setting up Linux with a few differences, mainly you don't get a desktop GUI out-of-the-box.

log in