How to compile and run mosh (Mobile Shell) on Dreamhost servers

mosh is a very nice way to connect to remote servers via the command line. It works in conjunction with ssh for authentication, but after that it's a totally new client/server protocol.

mosh helps people who move around a lot stay connected and also has some advantages over ssh in terms of responsiveness, which is nice on slower connections (like when you're connecting via your cell on a train).

Getting mosh working on Dreamhost isn't totally straightforward, but it is pretty simple if you are comfortable working on the command line. I'll give a step-by-step guide on installing and running mosh 1.2.2 with Protocol Buffers 2.4.1 below (there is definitely room for improvement, as you'll see, and suggestions are welcome).

Despite trying both .bash_profile and .profile, I couldn't get the export from the last line to stick. Same thing for the path settings. I'm not sure what kind of shell mosh invokes when it tries to run itself on the server, nor do I know how to get the environment variables to work there. Suggestions welcome!