Installing Mozilla's Firefox on Ubuntu

Why would you want to install the Mozilla version of Firefox?
Copy-and-paste terminal command
Demonstration Video
Notes
Command to remove Mozilla's version
Update Mozilla's version
Command Explanation
Other Methods

Why would you want to install the Mozilla version of Firefox?
There's usually no reason anyone would have to install the Mozilla version of Firefox. The Ubuntu repositories version receives security updates and is integrated with the filesystem. If you use the Mozilla version, you'll have to integrate it with the filesystem so that it launches properly and uses the right multimedia plugins, and you'll also have to do manual security updates.

Some people like to use the Mozilla version because they think it gives better performance. Others want a newer version of Firefox than their version of Ubuntu will offer. Whatever your reasons, this page should help you get the latest Mozilla build of Firefox installed on your system properly.

Copy-and-paste terminal command
The fastest and easiest way to get the Mozilla version of Firefox installed is copying and pasting the following command into the terminal.

This command assumes you've downloaded the Firefox .tar.bz2 file to your home directory (/home/username):

if [[ ! -f /usr/bin/firefox ]]; then sudo apt-get update && sudo apt-get install firefox; fi && if [[ -e ~/.mozilla ]]; then cp -R ~/.mozilla ~/.mozilla.backup; fi && sudo tar -jxvf firefox-3*.tar.bz2 -C /opt && rm firefox-3*.tar.bz2 && sudo mv /opt/firefox/plugins /opt/firefox/plugins.backup && sudo ln -s /usr/lib/xulrunner-addons/plugins /opt/firefox/plugins && sudo dpkg-divert --divert /usr/bin/firefox.ubuntu --rename /usr/bin/firefox && sudo ln -s /opt/firefox/firefox /usr/bin/firefox
That's it.

Demonstration Video

Notes
The instructions above also assume you've never installed the Mozilla version of Firefox to the /opt directory before. If you had installed Mozilla's Firefox 2 or 3 previously, then run the removal command (below) before running the installation commands (above).

Command to remove Mozilla's version
Sometimes people want to revert back to Ubuntu's Firefox and get rid of the Mozilla version of Firefox. If you want to do that, paste this command into the terminal:

sudo rm /usr/bin/firefox && sudo dpkg-divert --rename --remove /usr/bin/firefox && sudo rm -r /opt/firefox
It's very important that you paste that command. Do not retype it, as altering the last part of the command in any way (pressing Enter prematurely by accident, for example) could delete important system files or your entire installation.

I've generally found that Firefox profiles work (apart from no-longer-compatible extensions) from version to version of Firefox, but if you have a corrupt Firefox profile and if you used the cp -R ~/.mozilla ~/.mozilla.backup command to back up your Firefox settings before installing the Mozilla version, then you can restore your old settings with these commands:

mv ~/.mozilla ~/.mozilla.mozillafirefox
mv ~/.mozilla.backup ~/.mozilla

Update Mozilla's version
If you install Mozilla's version of Firefox, it won't update automatically the way the Ubuntu repositories' version of Firefox will. If you install Mozilla's Firefox 3.5 and then an update to 3.5.1 comes out, you will have to do the following:

  1. Close Firefox completely
  2. Press Alt-F2 to launch a Run dialogue
  3. In the Run dialogue, type gksudo firefox
  4. Go to Help > Check for updates
  5. Install the updates
  6. Restart Firefox when prompted
  7. Close Firefox
  8. Launch Firefox again in the normal fashion
It's very important that you use the command
gksudo firefox
to update and not sudo firefox. For more details about why, read this.

Also, this will do only mini updates, unless Mozilla decides to make the upgrade from Firefox 3.5 to Firefox 4 an incremental upgrade. If it is like any other release, you will have to redo this procedure to get Firefox 4 when it comes out.

Command Explanation
The command you pasted above is actually several commands strung together as one set. The && between each command tells the bash terminal to execute the next command if and when the previous command is successfully completed.

Here is an explanation of what the different parts of the command actually do.

if [[ ! -f /usr/bin/firefox ]]; then sudo apt-get update && sudo apt-get install firefox; fi
If the /usr/bin/firefox file doesn't exist, then double-check that the Ubuntu repositories version of Firefox is installed. This is important, because some later commands depend on the Ubuntu repositories version of Firefox being installed.

if [[ -e ~/.mozilla ]]; then cp -R ~/.mozilla ~/.mozilla.backup; fi
If the folder exists, make a recursive (all the subdirectories as well) copy of the Firefox settings folder. This includes bookmarks, history, saved passwords, and add-ons.
sudo tar -jxvf firefox-3*.tar.bz2 -C /opt
Extract the compressed Firefox download file to the /opt directory.
rm firefox-3*.tar.bz2
Delete (or remove) the original compressed download, now that its contents have already been extracted.
sudo mv /opt/firefox/plugins /opt/firefox/plugins.backup
In the newly extracted folder, there is an empty plugins folder. Let's rename that folder to make room for the real (non-empty) one.
sudo ln -s /usr/lib/xulrunner-addons/plugins /opt/firefox/plugins
Create a symbolic link between the real plugins folder and the plugins folder for our Mozilla-downloaded Firefox.
sudo dpkg-divert --divert /usr/bin/firefox.ubuntu --rename /usr/bin/firefox
Divert the original command to launch the Ubuntu repositories' Firefox to a new command, which is firefox.ubuntu, so if you want to launch the old Firefox, you still have the option.
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
Make a symbolic link from the Mozilla-downloaded Firefox to the firefox command, so your panel or menu launchers will launch this new Firefox and not the old one.

Other Methods
UbuntuZilla script
Add Firefox 3.5 to Ubuntu 9.04 through the PPA repositories

If you have suggestions or corrections for these tutorials, please post in this Ubuntu Forums thread or leave a comment on my blog.

I will not give help to people posting in the above places. If you require technical support, start a support thread on the Ubuntu Forums. That is the appropriate place to ask for help.