These are just the steps to install tor and the necessary software to make it run smoothly on your Ubuntu. For detailed info on what each parts does, you can always refer to the tor docs. This post is up-to-date with Ubuntu release 12.04.

1. Add the following to the end of your /etc/apt/sources.list file.

The format here is

deb http://deb.torproject.org/torproject.org <distribution> main

Since we are using Ubuntu 12.04 we will use precise for the distribution.

deb http://deb.torproject.org/torproject.org precise main

2. Import torproject.org repository GPG key.

gpg --keyserver keys.gnupg.net --recv 886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
sudo apt-get update

To keep the repository key up-to-date, install the debian package.

apt-get install deb.torproject.org-keyring

3. Install tor, tor-geoipdb, polipo, privoxy.

sudo apt-get install tor tor-geoipdb polipo privoxy

4. To Configure polio, first backup the original.

sudo mv -i /etc/polipo/config /etc/polipo/config.orig
sudo vim /etc/polipo/config

5. Add the following to the file or find those lines and uncomment them.

socksParentProxy = "localhost:9050"
socksProxyType = socks5
diskCacheRoot = ""
disableLocalInterface = true

6. (Optional but recommended) If you want a GUI frontend for tor install vidalia.

sudo apt-get install vidalia

Vidalia will show a message on how it should handle tor. You can choose complete takeover.

7. Append the following at the end of /etc/privoxy/config file or uncomment the line

sudo vim /etc/privoxy/config
forward-socks5   /               127.0.0.1:9050 .

Note that there is a space and a dot after 9050.

8. Now we have successfully installed and configured the tor and its family, we need to tell the browser to use the network.

Assuming that tor is running else, start tor by:

sudo /etc/init.d/tor start

Open Firefox, and install tor add-on. If you install the tor button add-on, then choose use polipo in the browser network settings. Else to configure manually go to Preference > Advanced > Network > Settings > Manual proxy configuration and enter the values for the following

HTTP Proxy: 127.0.0.1 Port: 8118
SSL Proxy : 127.0.0.1 Port: 8118
SOCKS Host: 127.0.0.1 Port: 9050
Choose SOCKSv5
No Proxies for: 127.0.0.1

And click test settings. If things went well you'll get Tor proxy test successful message.
You can check you IP address to see the difference.

9. Take about:config in the Firefox browser and set the value for network.proxy.socks_remote_dns to true to avoid DNS leaks.

NB: Its better not to run P2P software in tor network. The main purpose of tor is to provide anonymity for browsing. To make the tor network faster, you can consider running a tor relay on your system as well.

I highly recommend using the HTTPS Everywhere extension for Firefox from eff.org. It will make your browser to choose https protocol over http if the target server supports one.