I use the R Studio IDE to do many things, one of which is to serve local websites utilizing the blogdown package which is a fork of hugo. I write the code in R Studio and preview the site utilizing the blogdown::serve_site() command. This is the easiest way I know of previewing static HTML sites. Utilizing hugo R Studio coerces my browser to go to the location and my local site is previewed before my eyes.

Can I serve local sites natively with Ubuntu 18.04? How? I imagine it should be very simple. Searching online I can't find any simple way to do it though. If I simply open the static HTML files directly in my browser they showup wonky. All image links are immediately broken. Formatting of headings, hyperlinks, etc is not the same as when I serve the page locally with hugo.

EDIT - I did not really define my term 'simplicity'. There are two different approaches (so far) in the answers, one that is simplest to the end user, and one that is simple with regard to operations being performed by my computer. I like both approaches and will welcome answers utilizing any approach as I test them. Thank you.

  • 5
    Not sure what you mean by 'wonky'. When I open static HTML from a file, it shows up the way I expect.
    – user535733
    Commented Dec 17, 2018 at 17:43
  • @GeorgeUdosen To be fair, neither of those are a good match for the "simplest HTTP local server". There are plenty of far more lightweight / simple options available. Commented Dec 18, 2018 at 0:19
  • 1
    I support @user535733. You should investigate why the webpages are not displaying properly without a server, because those problems will inform what solution you need. Perhaps the pages contain URLs ("http://") to local files? In that case you need a server, or you change the URLs to relative paths and make sure the files exist relative to the viewed document. This implies that you need the whole web site file tree locally. Commented Dec 18, 2018 at 12:12
  • 1
    @Peter A. Schneider I drag my index.html file onto Chrome and this is the url file:///C:/Users/jason/hugoweb/public/index.html in my address bar. All image links are immediately broken. And formatting of headings, hyperlinks, etc is not the same as when I serve the page locally with hugo. Why, I have no idea?!? I'm open to answers. Commented Dec 18, 2018 at 14:06
  • 1
    if you have npm globally, install http-server globaly, then you can do in any directory in your terminal http-server to serve the files in localhost. (Default port 8080 but use -p to configure the port). Commented Dec 18, 2018 at 15:16

7 Answers 7


Ubuntu ships using python3 as its default, and they have gone to great lengths to make this extremely easy for us :D

To start the http server on port port simply type

python -m http.server port

If you want to share files and dirs, cd into whichever directory you want to serve

cd /my/html/files
python -m http.server 8080

Should you want to use an address other than the default you can use --bind

Ex: python -m http.server 8080 --bind will serve them at the address :)

Edit: Whether or not it truly was great lengths, I'll leave that to the reader

Also for your convenience here is a link to the docs https://docs.python.org/3/library/http.server.html

  • 1
    Is the port the XXXX in or is it the entire string Commented Dec 17, 2018 at 18:22
  • 2
    It will just be the XXXX but by default it will serve at I will update my answer to reflect how to bind to a different address
    – j-money
    Commented Dec 17, 2018 at 18:24
  • 4
    If you are using a very old ubuntu release: in python2 the module is called SimpleHTTPServer. note however that it always binds to you can only choose the port, thus use it exclusively if you are in a secure network.
    – Bakuriu
    Commented Dec 17, 2018 at 21:30
  • 1
    @KFleischer Enter Ctrl-C, or use the kill command
    – db-inf
    Commented Dec 20, 2019 at 10:51
  • 1
    This is very useful
    – Kinjal
    Commented Oct 2, 2020 at 4:13

Here is a list of HTTP server in one line. I am sure there is one that will fit your purposes/existing tooling.

Hereafter is a subset of the link, that contains in my opinion the most convenient ones.


python -m http.server 8000


ruby -run -ehttpd . -p8000


npm install -g http-server
http-server -p 8000


php -S
  • 3
    Nice answer. It provides information about many different options.
    – cezar
    Commented Dec 19, 2018 at 6:49
  • 3
    In python 2.7 the command is: python -m SimpleHTTPServer 8000
    – greuze
    Commented Jul 19, 2019 at 7:33
  • 4
    I strongly recommend the Node option (http-server). It is the most feature-rich one, supporting partial downloads and more, which is great if you are streaming videos for instance. Commented Sep 8, 2020 at 12:58
  • 1
    @BoraM.Alper if you need specific features, maybe you shouldn't look for a simple http server, but rather configure one to fit your needs.
    – Richard
    Commented Sep 9, 2020 at 13:05

One simple way to setup a static http site is to use darkhttpd

There is no package in ubuntu for that but the software is just one single source file that you can download with a tarball on the site or with git :

git clone https://unix4lyfe.org/git/darkhttpd
cd darkhttpd

Then run make and you have your darkhttpd executable. (Place it in /usr/local/bin to make it available to every user)


./darkhttpd /path/to/wwwroot


./darkhttpd --help

to get help about the command

One can specify directory or port to use and many other options.


sudo apt install apache2 will install the apache2 webserver. By default it provides access to index.html in the /var/www/html folder; replacing this file with whatever you want to host is the easiest way to do things, then you can navigate to on your local machine, or to your machine's IP address on your network and it will serve the pages.

  • after I install apache2 do I need to initiate the program with an apache2 command from the command line? Or does it run continuously in the background? I'd prefer not to run it continuously in the background. Commented Dec 17, 2018 at 17:46
  • 1
    you can turn it on/off/enable at startup by running (respectively) sudo systemctl start apache2 sudo systemctl stop apache2 sudo systemctl enable apache2. by default it does not run at startup, but does run after installation. If you change index.html while it is running, it will just serve the new version without needing a restart.
    – Minty
    Commented Dec 17, 2018 at 17:47
  • 7
    apache2 is way overkill for just a simple static site.
    – solsTiCe
    Commented Dec 17, 2018 at 17:50
  • 5
    I get the impression that simplicity and speed are the goal more than the weight of the program.
    – Minty
    Commented Dec 17, 2018 at 17:51
  • 1
    @Minty yes and OP has also to deal with permissions and stuff with Apache. The Python HTTP server solution is much simpler. Yours would be needed if the site was PHP based. :) Commented Dec 20, 2018 at 0:02

If you are a Google Chrome user, it can be as easy as using the Web Server for Chrome. Simply install it, launch it, click Choose Folder to select the directory that holds your static files.

  • 1
    This is a super underrated way of doing it
    – J Lewis
    Commented Dec 18, 2018 at 16:35
  • is there anything like this for firefox?
    – creanion
    Commented Aug 17, 2021 at 8:19
  • Meanwhile, there is also a native app. Commented May 17, 2023 at 3:11

If you do not want to remember the python command's arguments, use woof:

Description: share files through HTTP protocol
 Woof (Web Offer One File) is a tool to copy files among hosts. It can serve a
 specified file on HTTP, just for a given number of times, and then exits.

Features include:
 * it can share stuff "one shot" and exit just after he served that file.
 * it can share things among different operating system or different devices
   (e.g.: a smartphone), and allows one to upload files easily.
 * it can also show a simple html form in order to upload file (useful if the
   client hasn't a way to serve the file).

You can install it on Debian/Ubuntu with

apt install woof

And use as

woof kittens.png

It will print an URL to put into a browser at the other end.

  • wow so easy, upload and download
    – Pieter
    Commented Jul 23, 2019 at 2:52
  • 2
    Unfortunately, woof doesn't seem to be included in Ubuntu 20.04
    – ws6079
    Commented Oct 6, 2020 at 22:03

One of the simplest (and the most limited) solutions would be using netcat as described in this article:

while true; do { echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n<h1>hello world from $(hostname) on $(date)</h1>" | nc -vl 8080; } done

This example is serving on port 8080, serving on first 1024 ports will require you to use sudo. You can also serve a file this way simply by using cat filename.

For a more complicated example check out bashttpd.

Also note the differences between netcat-traditional and netcat-openbsd. Ubuntu provides both versions.

Not the answer you're looking for? Browse other questions tagged .