Start a webserver in current working directory using Ruby

If you’re working on a website and want to test the site and serve your current working directory as the website root, you can do it with Ruby:

ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 9090, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"

You can change the port to suit your needs. Make sure you have Ruby in your path.

For more on this, see this discussion on Stack Overflow, where I found this. Thanks to the people there.

Tags: