Every time I need to do this, I forget where I found it. This information is copied from here.

Vorbis ogg:
vorbisgain -arfs *

mp3 (using mp3gain):
find -type d -exec sh -c "mp3gain \"{}\"/*.mp3" \;

mp4 and mp3:
find -type d -exec sh -c "mp3gain \"{}\"/*.mp3" \;

find -type d -exec sh -c "mp3gain \"{}\"/*.mpc" \;

flac: just use the –replay-gain option when encoding or use the following (treating all the flacs as one album!):

find originals -name "*.flac" -type f -print0 | xargs -0 metaflac --preserve-modtime --add-replay-gain

or you can create the following small script and call it with the name of your base directory (/srv/music, or something like that). This will treat all songs in one directory as one album.

for dir in `find $basedir -type d`; do
ls $dir/*.flac >/dev/null 2>&1 && metaflac --add-replay-gain $dir/*.flac