The easiest way to do this is to edit the networking config file:
Run the following command: sudo nano /etc/network/interfaces
Find your adapter (should be eth0 or wlan0 depending on if you're hard-wired or wireless), for example: iface eth0 inet static
Edit (or add in if it doesn't exist) this line: gateway [gateway ip]
So, if your gateway IP is 10.0.1.1 then you'd put in gateway 10.0.1.1
Next, save and restart the networking services: /etc/init.d/networking restart (or /etc/init.d/network)
Note, you might have to chmod 400 the file so it's read-only, but this is only if the above steps get changed by Ubuntu's network management setup.
To test to see if this works, try to ping the gateway. If pinging works, run the following command: route -n and you should see the gateway IP listed.