Basic Elixir | Installation, mix, create project, module and method
Elixir is a dynamic, functional language designed for building scalable and maintainable applications. Built on the Erlang VM, it inherits Erlang's excellent support for concurrent and fault-tolerant systems. This tutorial will guide you through the basics of Elixir, including installation, project creation with Mix, and an introduction to modules and methods.
1. Installing Elixir
Before diving into Elixir, you need to have it installed on your system. Follow these steps:
On macOS:
Open Terminal.
Use Homebrew to install Elixir:
brew install elixirVerify the installation:
elixir --versionOn Linux:
Update your package index:
sudo apt updateInstall Elixir using your package manager:
sudo apt install elixirVerify the installation:
elixir --versionOn Windows:
Download the installer from the official website.
I did use Scoop for easier installation. first install erlang then elixir.
Follow the installation instructions.
Open a command prompt and verify the installation:
elixir --version2. Creating a Project with Mix
Mix is Elixir's build tool, essential for creating projects, managing dependencies, and running tasks.
Steps to Create a New Project:
Open your terminal or command prompt.
Run the following command to create a new Mix project:
mix new hello_elixirThis will create a directory named
hello_elixirwith the necessary project structure.Navigate to the project directory:
cd hello_elixirRun the project to ensure everything is set up correctly:
mix run3. Understanding Modules and Methods
Modules in Elixir are containers for related functions (methods). They help organize your code and make it reusable.
Example of a Simple Module:
Open the file
lib/hello_elixir.exin your project directory.Replace its content with the following:
defmodule HelloElixir do
# This is a simple method that greets a user
def greet(name) do
"Hello, #{name}!"
end
endSave the file.
Running the Code:
Open
iex, Elixir's interactive shell, inside your project directory:
iex -S mix
// in windows use iex.bat -S mixCall the method from your module:
HelloElixir.greet("World")Output:
"Hello, World!"4. Summary
In this tutorial, you:
Installed Elixir on your system.
Created a new project using Mix.
Learned about modules and defined your first method.
Elixir's simplicity and powerful features make it an excellent choice for building modern applications. Stay tuned for more tutorials as we dive deeper into Elixir's ecosystem, covering topics like pattern matching, processes, and OTP.


