# Installing R and JAGS on Ubuntu OS

HOME I recently tried installing R and JAGS on my machine running Ubuntu. I wanted to test my BEST and wiqid packages with the new version of JAGS on Ubuntu. It took me a while, but I finally found a simple way to do this which might be of interest to others.

I already had R and JAGS 3 installed, together with the rjags package version 3. Installing the rjags package within R (or updating it with update.packages()) installs the new version of rjags, v.4, which requires JAGS 4 and throws an error if it isn't found. But the Ubuntu repository still has JAGS 3, so you cannot update JAGS with Ubuntu Software Center.

I was running the Long Term Support (LTS) version of Ubuntu, Trusty, so decided to upgrade to the latest, Wily, before going further, but I found that crashed regularly, so reinstalled Trusty. At this point I had a clean OS install.

The simplest way to install R, JAGS and rjags is to use Michael Rutter's Personal Package Archive (PPA). Update 2017-03-13: This solution is not available for all versions of Ubuntu; currently only for Precise, Trusty and Wily. Check the entry for rjags on Michael's page for the latest info. You can do it all with 3 lines of code in the Terminal:

sudo add-apt-repository ppa:marutter/rrutter
sudo apt-get update
sudo apt-get install r-cran-rjags

Installing r-cran-rjags in this way will automatically install both R and JAGS 4.

#### If you already have JAGS 3 installed

I actually tried to install JAGS 4 on the machine before reinstalling Ubuntu. On Windows, JAGS 4 is installed in a separate folder to JAGS 3, so you can happily have both on your machine and both old and new versions of rjags will work. On Ubuntu, the new obliterates the old ... mostly! When I tried this, I got an error when I tried to load rjags in R: "unable to load shared object: ... rjags.so" and a further note about an "undefined symbol".

The apparent reason for this was components of JAGS 3 which had not been removed when JAGS 4 was installed, as explained by Martyn Plummer here. So I uninstalled and purged, and then checked for remaining files:

sudo apt-get --purge autoremove jags
/sbin/ldconfig -p | grep jags -

I still had stuff in /usr/local/lib, so navigated to there and manually deleted the JAGS directory and all the jagslib* files (with sudo rm -r as they are read-only). Then reinstalled JAGS 4 from Michael Rutter's PPA and it all worked.

#### Installing RStudio

In Windows, I like to use Notepad++ with NppToR, but those aren't available for Linux distros, so on Ubuntu I use RStudio.

I downloaded the latest version of RStudio from their download page and opened it with Ubuntu Software Center. On Trusty, that worked out of the box, but not on Wily. I tried to open it in the Terminal, and got an error message about libgstreamer. This needs to installed separately as described here.

Updated 13 Mar 2017 by Mike Meredith