How to use CLI Badger Tool?

Hello all!
Sorry i am a new with Badger Database.
I am working with golang and badger database, please recommend me for use CLI Badger Tool.
When i run main.go file in badger library i can get all information look like image below.


But i do not understand for use it in my project
When i try type command it export error message : badger: command not found
Please !!!

If any topic that the same my topic please recommend me.
Thanks!

Hey @hunght, Welcome to the Dgraph Community!

Badger is an embeddable key-value store. It’s CLI tool is not meant for DB operations like inserting an entry or getting a value. It is for more general purposes like creating a backup of whole DB, restoring it, testing(benchmarking) badger etc. For details on how to use Badger, you can refer to its README.

Feel free to ask more questions.

1 Like

@ahsan Thanks for your support
But how to type command badger on terminal ?
is it install badger && go ?

Hi @hunght,

The command, cd badger && go install will install badger and create a binary with the name badger inside directory pointed by $GOBIN. It is usually set to ~/go/bin
To run badger through terminal, you can either run the badger executable inside GOBIN or add directory containing badger executable to $PATH variable.

Related link: linux - How to properly set Environment variables (golang on Manjaro) - Unix & Linux Stack Exchange

2 Likes

@rajas thanks for your support
The command, cd badger && go install, is it equivalent go get github.com/dgraph-io/badger/v2 ?
Thanks!

Hi @hunght,

Not in this case. The go get command downloads the package and tries to install it.
The other command, cd badger && go install is run when the user is already inside github.com/dgraph-io/badger directory.
To generate the badger executable, use the cd badger && go install command.

2 Likes

@rajas
Sorry !
i added directory containing badger executable to $PATH variable.


is it right way ?

Yes. It’s one of the right ways. There are many.

To make things easier, installation instructions for Badger CLI tool and Badger library have been separated in Badger README.

Related PR: fix(README): Change instructions for installing badger in README.md by vmrajas · Pull Request #1495 · dgraph-io/badger · GitHub