How to Install Laravel On Mac Or Ubuntu Step By Step

Learn How to Install Laravel On Ubuntu Mac Step By Step with this guide.

If you are beginner on laravel and want to install laravel on your mac or ubuntu linux machine then this tutorial perfectly fits for your requirements.

For installing laravel on mac or ubuntu, we require PHP and composer on our machine.

So follow all the below steps to create your first basic project on laravel.

Step 1. Checking PHP version

First of all, let us check current installed php version on your machine. So open up your terminal.

Inside it, write down the following command and hit enter.

This command will give us the current version of the php. In my case I got the following results.

So, I have version number 7.2.14 on my system. For installing laravel, we need to have minimum version of PHP as described in the official documentation.

To check official recommended version, click here to go to official documentation.

If your machine have older version than the official recommendations, then you need to update php version. Otherwise no need to worry.

How to update PHP ?

You can have several ways to update your php version. For example, using homebrew or may be directly from the terminal.

For mac

If you are using Apple Mac, then I highly recommend you to use homebrew for updating PHP.

Go to the homebrew page using this link. Here, you will find one command to install homebrew on your mac.

Following is the command

Hit above command on your terminal and press enter. System will download homebrew and will install it automatically.

After this, type the below command to install PHP version 7.1,

You can replace 7.1 with the version number, you want to install.

Now again type command php -v . This time you should get the proper php version. If not then do little research on internet and try until you get proper php version in the results of php -v

For Ubuntu or Linux

To install php 7.3 version, type the below command in terminal

You in the last line, you can replace 7.3 with desired version.

Again check php version with help of, php -v command.

It is necessary to get greater or equal php version then the official recommendation in the results of “php -v” command.

Once your php version is ok with official version of laravel documentation, you are ready to install composer.

Step 2. Installing Composer

First of all, download the composer using the below command

You can check the official documentation for downloading composer here.

You should get the below lines when you have successfully installed composer.

Now let us put our composer in the global directory. For this, run the below command

You can find this command on this official link.

Now if you fire the below command

then you should get the below output

Ok, so till now, we have got the latest php version and have installed composer.

Step 3. Installing the Laravel

Write the below command in terminal

It will take little bit of time to download and install laravel.

Once this process is finished, we need to set up environment variable $PATH.

$PATH on Mac

If you are using mac, then your $PATH should like this according to documentation

$HOME/.composer/vendor/bin

Now I am using oh my zsh in my terminal. If you are also using this then run below command

If you are not using oh my zsh, then you can try something like

sudo vi ~/.bashrc or sudo vi ~/.bash_profile

Once you hit above command, you will be asked for password and then a text something like below will be opened

Now press i so that you will be able to edit above file.

Write down below line

below # export PATH=$HOME/bin:/user………

Then press Esc (escape) key, so that you can save the changes. For saving changes, press (:wq) this will written at the end of the file.

So new text should look like below

You can see that I have added a line below # export PATH=$HOME/bin:/user……… and also :wq is there at the end.

Now press enter and your $PATH is now updated with composer.

$PATH on Ubuntu

If you are using mac, then your $PATH should like this according to documentation

$HOME/.config/composer/vendor/bin

Now hit following command

Then system will ask you for password and then it will show you some texts.

At the end of this text, type

export PATH=”$PATH:$HOME/.config/composer/vendor/bin” 

and then save.

Step 4. What if I am facing issue in environmental  variable $PATH

Setting this variable is the little tricky process for both mac and ubuntu.

If you are facing issues then there is one solution for this.

Whenever you open your terminal simply run the below command on mac

and if you are on ubuntu then run

Now you should be able to create new laravel project.

One drawback of this solution is that our settings will be destroyed when you close your terminal. So you need to repeat this process every time you open new session of terminal.

Now let us check if laravel is successfully installed or not. For this, simply type

laravel and hit enter.

You should get below lines

If you are getting above lines then congratulations, you have successfully installed laravel on your machine!!

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *