Creating a Basic Yesod Project Using Command Line Tools on Linux

Last updated:

After you've installed haskell, cabal and yesod (see the other tutorials).

$ yesod init

enter information like project name and database type.

enter the newly created directory:

$ cd <project_name>

edit your database config (i.e. set database username and password and database name(it's ok if the database doesn't exist yet)). If you choose MySQL, do:

$ vim config/mysql.yml

Then create the database itself: (replace your_password with your root password and database_name with your database name)

$ mysql -u root -pyour_password -e 'create database database_name default charset utf8;'

Now edit file config/models and define the models which will be used to create your database structure. An example:

    ident Text
    password Text Maybe
    UniqueUser ident
    deriving Typeable
    email String
    user UserId Maybe
    verkey Text Maybe
    UniqueEmail email
    title String
    text Text
    author UserId Maybe
    date_added UTCTime

Now start the server:

yesod devel

You probably have some errors in the models definitions. Just edit it and save the file and your application will re-compile.

The usual cycle is:

  • edit a file
  • view server info to see whether there's been errors ( when you start a server using yesod devel, you'll see lots of info printed to stdout. This is what I call "server info". Info gets updated automatically every time your edit a file)
  • fix errors (if present)
  • repeat


  • Permission denied when running cabal install or cabal-dev install

    $ sudo chown $USER ~/.cabal -R
  • Failed to install mysql bindings (something like mysql-simple- depends on mysql- which failed to install.)

You need to make sure you have mysql and mysql_config commands installed in your box: (If on Ubuntu/Debian:)

    $ sudo apt-get install mysql-server
    $ sudo apt-get install libmysqlclient-dev


Dialogue & Discussion