Skip to content

Instantly share code, notes, and snippets.

@aidos-dev
Last active April 8, 2023 17:09
Show Gist options
  • Save aidos-dev/ba736dd9124495e91bd704a63ba79ff0 to your computer and use it in GitHub Desktop.
Save aidos-dev/ba736dd9124495e91bd704a63ba79ff0 to your computer and use it in GitHub Desktop.
How to install migrate for CLI (golang-migrate)

The easiest way to install golang-migrate for CLI on Linux (Ubuntu/Mint)

Introduction

The title says that this article will give you the easiest way to install golang-migrate program.

Somebody might have different opinion because they were lucky to install it from the first attempt just by pasting couple of commands into the console.

But I was not so lucky. While trying to install this program by the official instruction from the GitHub repository of "golang-migrate" I faced a lot of errors.

https://github.com/golang-migrate/migrate

Like everyone I was looking why this errors occured and how to solve them. And I found that a lot of people have simillar issues and solutions are quite complicated.

But I found they way of installation that will help you to avoid all these errors and will save you hours! That is why I believe that this way is the easiest one :)

Installation

We need to download the source code of the program from the GitHub, create an executable file of the program and place it in your Linux OS:

  1. Open the terminal
  • Choose the directory where you want to download it or create a new one where you want. This is not very important, since we will create a binary file and then move it to another place.
  1. When you inside the directory of your choise, run the command:
git clone https://github.com/golang-migrate/migrate.git
  1. Then go inside the downloaded directory with the command:
cd migrate
  1. Create an executable file by running:
make build
  1. Move the executable (binary) file to the directory where all your binary files live. This directory path might be ./usr/bin or /bin. Depending on the /bin directory location run one of this commands:
mv ./migrate ./usr/bin

or

mv ./migrate /bin

Chances are that your OS might request for admin permission. In this case just use the magic word :)

sudo mv ./migrate ./usr/bin

or

sudo mv ./migrate /bin

And that's about it! =)

Thank you a lot for reading this guide. I really hope it will save you hours that I spent before finding this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment