A One-Line Web Server in Ruby

April 11, 2010

Inspired by a tweet, here's how to serve the current directory over HTTP with a single line of Ruby:

ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd).start'

That's it. Point a browser at http://localhost:3000 and you'll see a directory listing. It's great for quickly sharing files at a conference, previewing static sites, or any situation where you need a throwaway web server with zero setup.

Questions or thoughts? Get in touch.