Tuesday, March 1, 2011

A Geekier Way to Set Your Default Browser in Linux

One of the things I've disliked about having programs from multiple desktops installed is that you need to change the default browser from more than one settings configuration. And then, some programs use their own browser settings, requiring you to use them. And some proprietary applications, such as skype, don't have any apparent way to change the default browser.

This can be very tedious if you like to change browsers frequently.  I tend to try out the beta builds for firefox for a few days before switching back to chromium.  So, I've put together a useful little trick for working around the problem. Here's how you do it under Arch Linux.

First, create a new text file named "browser" in your /usr/bin directory as root.  Then, put the text below into the text file:

chromium "$@"

Replace chromium with the command for whichever browser you prefer to use.  Next, go to your /etc/profile.d folder (most systems /etc/profile) and create a new file, name browser.sh (or whatever .sh you prefer).  Set its contents to this:

export BROWSER="/usr/bin/browser"

And then sign out from your session and reboot.  Most applications will use what you set in /usr/bin/browse as the default browser.  For the ones that don't, you manually set them in the application preferences and the preferences for GNOME and KDE.  After you've finished setting that all up, you will only need to change /usr/bin/browser in order to change the default browser.

However, the instructions above will change your default browser for the entire system for any applications that observe the BROWSER environment variable.  If you have multiple users on your system, you may wish to instead export the BROWSER environment variable in the .bash_profile or .bashrc files in your home directory.