Installation
This guide will help you get started in order to install Marten and its dependencies. Let's get started!
Install Crystal
Marten is a Crystal web framework; as such Crystal must be installed on your system. There are many ways to install Crystal, but we'll only highlight what we think are the most common ones here for the sake of simplicity: using Homebrew (macOS or Linux) or the APT package manager (Ubuntu, Debian). Please refer to the official Crystal installation guide if these methods don't work for you.
Using Homebrew
On macOS or Linux, Crystal can be installed using Homebrew (also known as Linuxbrew) by running the following command:
brew install crystal
Using APT
On Ubuntu, Debian or any other Linux distribution using the APT package manager, Crystal can be installed by running the following command:
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
Using pacman
On ArchLinux and derivates you can install Crystal and the shards
command line tool through Pacman:
sudo pacman -S crystal shards
Install a database
New Marten projects will use a SQLite database by default: this lightweight serverless database application is usually already pre-installed on most of the existing operating systems, which makes it an ideal candidate for a development or a testing database. As such, if you choose to use SQLite for your new Marten project, you can very probably skip this section.
Marten also has built-in support for PostgreSQL and MySQL. Please refer to the applicable official documentation to install your database of choice:
Each database requires the use of a dedicated shard (package of Crystal code). You don't have to install any of these right now if you are just starting with the framework or if you are planning to follow the tutorial, but you may have to add one of the following entries to your project's shard.yml
file later:
- crystal-pg (needed when using PostgreSQL databases)
- crystal-mysql (needed when using MySQL databases)
- crystal-sqlite3 (needed when using SQLite3 databases)
Install Marten
The next step is to install the Marten CLI. This tool will let you easily generate new Marten projects or applications.
Using Homebrew
On macOS or Linux, Marten can be installed using Homebrew (also known as Linuxbrew) by running the following commands:
brew tap martenframework/marten
brew install marten
Once the installation is complete, you should be able to use the marten
command:
marten -v
Using AUR on ArchLinux and derivates
Assuming you use some AUR helper (yay
in this example) it will be as simple as:
yay -S marten
Once the installation is complete, you should be able to use the marten
command:
marten -v
From the sources
Marten can be installed from the sources by running the following commands:
git clone https://github.com/martenframework/marten
cd marten
shards install
crystal build src/marten_cli.cr -o bin/marten
mv bin/marten /usr/local/bin
Once the above steps are done, you should be able to verify that the marten
command works as expected by running:
marten -v
Next steps
Congrats! You’re in.
You can now move on to the introduction tutorial.