It's so easy on Windows, but I know next to nothing about Ubuntu.
It's the same procedure in Windows or Linux, actually, only the location of the bitcoin.conf file changes.
Locate your bitcoin.conf file, it should be ~/.bitcoin/bitcoin.conf
If you're not familiar with the UNIX filesystem paths and hierarchy, and/or using the GUI:
- ~ is your home directory, i.e. /home/<your-username>
- .bitcoin is a hidden directory, so you may need to change display settings if it's not showing up
Then use your favorite editor and add or edit this line:
datadir=/<path>/<to>/<your>/<datadir>