June 15, 2011: In Ubuntu 11.04, you can add MP3 support to the Ubuntu supplied version of SoX with the libsox-fmt-mp3 package, so all of this is now unnecessary.
For as long as I remember in my Linux career I've been using Sound eXchange (SoX) to convert audio files from one format to another — in particular, converting to MP3 format so that I could play them on my audio player. As I've noted before, this isn't an easy task. Distributions are understandably reluctant to deal with the licensing and patent issues encumbering MP3 files and so let you figure it out for yourself.
The following seems to be the easiest way to do it. I got the basic process from Inverted Egg, but I'm not going to convert put everything into a .deb file, since it will just get rewritten with the next update.
Here we go:
- Download the SoX source tarball. It doesn't matter where you put it, we'll assume it goes to /home/yourname/Downloads.
- Open a terminal window and become root:
$ sudo -i
You'll get prompted for the password.
- Go to a useful directory to unload the source:
# cd /usr/local/src
- Unpack the tarball. Note that the version name will occasionally change:
# tar xvzf /home/yourname/Downloads/sox-14.3.1.tar.gz
- Load Ubuntu's version of SoX into the system, if it's not there already, along with the lame library and header files, which are responsible for mp3 processing:
# apt-get install sox liblame0 liblame-dev
- Find all the packages that Ubuntu's SoX needed to compile, and install those you haven't installed already:
# apt-get source sox
That's why you needed to install Ubuntu's SoX in the first place.
- Now do the usual installation stuff:
# cd sox-14.3.1 # ./configure # make # make install
- Your new version of SoX is in /usr/local/bin/sox. Make sure it works, i.e. it converts files to mp3, and then delete Ubuntu's version of SoX:
# apt-get purge sox
And you're done. Of course, every once in a while you're going to go back and look for updates, right?