Skip to content

Running Oracle XE on Mac OSX using virtualised JeOS

So Oracle in its wisdom doesn’t have Mac OSX version of its free database. This is of course really annoying to Mac users who need to develop systems that use Oracle databases – Oracle XE is a great little database especially for development environments. Recently I found myself in a situation where I would be needing to bind a Hibernate object to a PL/SQL function in the target Oracle database rather than a table or view per se. As the function call is database specific, when developing the application I needed to use an Oracle database and could use e.g. HSQL or MySql as a substitute Oracle DB for development purposes. Oracle XE is a great way out here because it fully supports PL/SQL packages and functions and procedures.

I was off the client site so I couldn’t rely on a fast connection to their development databases. I just wrote a dummy function that was called the same as the real function with the same input and output parameters and instead of the complex function body it just wrapped a simple mock table of test data. Problem solved, Oracle XE to the rescue. But first you have get Oracle XE running on your Mac, this is what the rest of this article is about, because you can’t just download an Oracle XE edition for the Macintosh.

Virtualisation is great – use a Linux VM

However modern Virtualisation is your saviour. Put simply, you can use a virtualisation tool like Parallels, or my choice, VMWare Fusion, to run a virtualised version of Linux that contains the Oracle XE instance.

Because VMs can waste a bit of your local resources, luckily there is a specialised version of Ubuntu designed for running as a virtualised machine of this type. Its called JeOS (pron. Juice, apparently). It doesn’t have an X-window environment, just the shell, so it’s pretty lightweight and can run, with Oracle XE, in less than 512MB of memory. Perfect for getting a copy of Oracle XE onto your Macbook Pro.

It will however, eat up a couple of gigabytes of disk space, up to the maximum limit you choose for your disk size in the VMWare configuration. However it will only use the current amount of disk needed, as VMWare will expand the size of the image as needed (I’ll just assume that Parallels does something similar).

Setting it up – basic instructions

This page here – has a great set of instructions for getting JeOS installed and configured with Oracle XE on it.¬†Follow the instructions there exactly – but only to the point where you install and configure Oracle XE – don’t go further than that.

Make sure you configure plenty of swap space as outlined in the instructions.

Setting it up on standard Ubuntu/Debian

If you are running a full Ubuntu or other Debian based instance, the instructions are somewhat simpler. Install it as per normal in your VM. But make sure your swap space is twice the memory you have assigned to the VM! Oracle XE demands things to be like that.

Add

deb http://oss.oracle.com/debian unstable main non-free

to /etc/apt/sources.list and then:

$ wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle  -O- | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install oracle-xe

These instructions were cribbed from here.

After installing and configuring Oracle XE

After you run the XE configuration (‘$’ represents the Unix shell prompt and should not be typed);

$ sudo /etc/init.d/oracle-xe configure

If you’re running on JeOS don’t yet make the machine “headless”! Or you might find there are issues with the “Apex” application. The problem is that the Apex application, which is a useful web-based administration program for Oracle XE (especially for developers who don’t want to be forced to use sqlplus for all their database administration), will only allow connections from localhost – and you don’t have X-window, or a browser, to access it (I don’t know if lynx will work with Apex and I wasn’t going to try).

Get SSH installed

First get SSH installed in JeOS so you can get to the command prompt remotely:

$ sudo apt-get install ssh

Find out the VM’s IP address

Now, if you type ifconfig (/sbin/ifconfig if that’s not found on your path) you will be able to determine the IP address of your VM running on your Macintosh. At this point you can connect to the VM using ssh from a Macintosh terminal window:

$ ssh username@ip_address

Actually, at this point you can go ahead and make the machine headless, if you want. I would recommend not to do that until you’re sure of everything you’ve configured.

Configure environment to run sqlplus

After you’ve logged back into the running Linux VM using ssh from the Mac Terminal, the next thing is you’ve got to get sqlplus access working to the XE instance you installed. Funnily enough, although the .deb file that is installed off the Oracle site creates an oracle user, it doesn’t in any way set that user up so you can use the command line tools. SO you can’t just su – oracle and get a functional environment.

Anyway, you will need to do two things to your environment; add the ORACLE_HOME environment variable and set up your PATH so it can find sqlplus.

$ export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
$ export PATH=${PATH}:${ORACLE_HOME}/bin

You should add these two lines to your .profile or .bash_profile file – probably best for the ‘oracle’ user that the installation will have created. But you can actually set this up for any regular user that you configure in this VM. You can also just type them at the command line to get them in your current environment, if you have to.

Configure Apex to accept non-localhost connections

The web-based administration software for XE, called “APEX”, only binds to localhost. This is a big hassle if your VM copy of Linux (like JeOS) doesn’t have a GUI, because you don’t have a browser (lynx/links excluded, I did not try those!). ¬†However, you can make Apex bind to the “external” IP address for your VM, but you’ll need to use sqlplus.

To run sqlplus, do the following:

$ sqlplus system@XE
  Enter password:

Enter the password you specified at the ‘oracle-xe configure’ step above.

At the SQL prompt, enter the following command:

SQL> EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);

Now you’ll have to stop and start Oracle to make the configuration active:

$ sudo /etc/init.d/oracle-xe restart

After which, if you type

$ netstat -tna

You should find a line

tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN

This indicates a process is listening to the port 8080 on all IP addresses for connections coming from any other IP address. Assuming you specified port 8080 at the ‘oracle-xe configure’ step. Sometimes I use 8888 especially if I have a Tomcat instance in the same VM, as Tomcat will also like to run on 8080 and I’d prefer it if it did.

Test and use Apex

Test this connection in your browser, in my case, the address was 10.1.2.17, but you will have to substitute your own VM’s IP address – http://10.1.2.17:8080/apex. I like to make an /etc/hosts entry that points to this address as ‘oracleXE’. That way I can use a symbolic name in my jdbc connection strings and actually switch which instance of XE I am using depending which VM I’ve fired up without editing the jdbc configuration of the application under development – I just change the /etc/hosts entry instead.

Anyway once you connect to apex you can login using the user name and password you set up during your XE install and configuration process (same as you used for sqlplus). The users will be sys and system, you can use them to create new users to contain your databases for development.

The same IP address as above will be used to connect to your Oracle database from the programs you are developing. The default port should be 1521 and the SID should be XE.

Enjoy!