Unable to install golang migrate library on Ubuntu 20.4

Viewed 5694

Steps followed as in the documentation

$ curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
$ echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/migrate.list
$ apt-get update
$ apt-get install -y migrate

The error i'm getting in the first step is

    sudo curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0E: This command can only be used by root.
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100  3954  100  3954    0     0   2244      0  0:00:01  0:00:01 --:--:-- 17651
(23) Failed writing body

Please help me with this?
4 Answers

this is the easiest method to download a pre-built binary and move it to a location on your system path:

$ curl -L https://github.com/golang-migrate/migrate/releases/download/v4.14.1/migrate.linux-amd64.tar.gz | tar xvz

$ mv migrate.linux-amd64 $GOPATH/bin/migrate

For quickinstall;

$ curl -s https://packagecloud.io/install/repositories/golang-migrate/migrate/script.deb.sh | sudo bash
$ apt-get update
$ apt-get install -y migrate

It's strange that there is no installation text.

  1. run either of these command
$ go get -u -d github.com/golang-migrate/migrate/cmd/migrate

or 

$ go get -u -d github.com/golang-migrate/migrate

this would download golang-migrate to your GO_PATH, e.g. /home/ubuntu/go/pkg

  1. cd to this folder: ( the v4@4.14.1 may change on your actual situation)
$ cd ~/go/pkg/mod/github.com/golang-migrate/migrate/v4@v4.14.1/cmd/migrate
  1. go install .

wait seconds and then you will see migrate command available in your GO_PATH:

$which migrate     // ->   /home/siwei/go/bin/migrate

But I love Rails' migration. It's more advanced.

You need to download the source code of the package from GitHub (https://github.com/golang-migrate/migrate), build it and place the built utility at the directory with binary files.

 git clone https://github.com/golang-migrate/migrate.git
 cd migrate
 make build
 mv ./migrate ./usr/bin
Related