Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
qmacro
Developer Advocate
Developer Advocate
Install the btp CLI to be ready to start exploring its features and functions.

The SAP BTP Command Line Interface (aka btp CLI) is a great tool for administering accounts and related resources on the SAP Business Technology Platform (BTP). It's a super fit for devops and cloud native activities as it's a command line tool that is both interactive and scriptable. And as we all know, #TheFutureIsTerminal, right?

It's available for download from the cloud section of the SAP Development Tools site - now would be a great time to install it to start exploring and understanding what it can do for you.

The relevant documentation on the btp CLI is here: Account Administration Using the SAP BTP Command Line Interface (btp CLI) [Feature Set B].

If you're not sure how you're going to use the btp CLI for real yet, and just want a throw-away experience for now, this post is what you need - it will take you through installing it in the cloud using a script that you can then use in your own command line context later. All you'll need for now is a BTP trial account with Feature Set B. You'll be installing and using it within the SAP Business Application Studio (App Studio) context.

Set up


Log into your trial account on BTP and jump to the App Studio context from the welcome page. Create a new dev space - you don't need anything special, just the "Basic" type will do - and jump into it when it's started up.

Make this your CLI in the cloud - you don't need any file explorer, or even any file editor, so click the Explorer "folders" icon to toggle it off, close any open files (including the Welcome page) and open a Terminal, dragging the vertical divider to the top for maximum space. That's better!


You can just download the btp CLI from the SAP Development Tools site mentioned earlier, which would be fine. But I prefer a script to help me not only download and unpack it, but also to let me check what the latest version is, and also have a slightly more flexible version management approach. So I wrote one, and we'll use that together here.

It's available in the SAP Tech Bytes repository branch associated with this post: getbtpcli, and we'll grab it from within our App Studio terminal session now.

Get the download script


In your terminal, run this to grab the script:
curl \
--remote-name \
--location \
--url "https://raw.githubusercontent.com/SAP-samples/sap-tech-bytes/2021-09-01-btp-cli/getbtpcli" \
&& chmod +x getbtpcli

This uses curl to fetch the raw script file, saving it to a file of the same name, following any HTTP redirects that the server might return. It then sets the executable mode bit for the file so we can run it.

Run the download script


You can run the script in test mode, just to get it to tell you what the latest version of the btp CLI is. Do this now:

./getbtpcli --test


This will give you something like this:
Latest version is 2.8.0

Running the script without the test mode option will download and install it. Do that now:

./getbtpcli


This will ask you first to confirm your acceptance of the licence agreement, before downloading and unpacking the executable; it will tell you what the version is, too:
Proceed (with Enter) only if you accept the SAP Developer Licence 3.1
(see https://tools.hana.ondemand.com/developer-license-3_1.txt) ...
Latest version is 2.8.0

Where has the executable been placed? By default, the getbtpcli script will put it in a bin/ directory in your user's home directory (i.e. $HOME/bin/). Have a look now to see:

ls -l $HOME/bin/


This will output something like this:
lrwxrwxrwx 1 user group        9 Sep  1 09:40 btp -> btp-2.8.0
-rwxr-xr-x 1 user group 10868080 Jul 29 15:09 btp-2.8.0

Note that there are two files; the actual binary, called btp-2.8.0 and a symbolic link, btp, which points to that binary. This is so that in the future we can have a new version of the binary, use that by default (by setting the symbolic link btp to point to that new one), but keep the old one too. There may be circumstances when you need a different version of the binary (the client-server design of the btp CLI is very flexible and powerful).

You can of course add the bin/ directory to your shell's $PATH, so that you can just invoke btp as-is. Do it for this particular terminal session right now, like this:

export PATH="$PATH:$HOME/bin"


You can also add this line to the .bashrc file in your home directory; this is executed each time you start a new session.

Invoke the btp CLI for the first time


Running btp now will give you a nice welcome message that looks something like this:
Welcome to the SAP BTP command line interface (client v2.8.0)

Usage: btp [OPTIONS] ACTION [GROUP/OBJECT] [PARAMS]

CLI server URL: not set
User: not set
Configuration: /home/user/.cache/.btp/config.json

You are currently not logged in.

Tips:
To log in to a global account of SAP BTP, use 'btp login'. For help on login, use 'btp --help login'.
To display general help, use 'btp --help'.

OK

The welcome message confirms the version you have, and also gives you information about what server you're connected to and what user and login information is currently active, if any.

Wrapping up


You now have the btp CLI installed in a convenient place where you can start to try things out. You also have a script that you can use to keep your btp CLI up to date.

Let me know in the comments whether you've managed to set up the btp CLI like this, and if you have your own way of managing versions and downloads. I'd love to see how you do it! Also, if you have any questions about getbtpcli itself, feel free to ask - no question is too simple.

In the next post we take our first steps with the btp CLI by logging in and understanding what's going on: SAP Tech Bytes: btp CLI – logging in.

Updates


10 Nov 2023 - If you're a macOS user, you can now install the btp CLI via Homebrew, which is pretty awesome:
brew install --cask btp

Nice!





SAP Tech Bytes is an initiative to bring you bite-sized information on all manner of topics, in video and written format. Enjoy!
9 Comments
MortenWittrock
Active Contributor
In the words of Success Kid:

qmacro
Developer Advocate
Developer Advocate
Great comment is great 🎉
christian102094
Participant
Nice information!

Didn't work for me in macOS Big Sur, something about -P option missing in grep command.

I got it working by changing grep for perl: https://github.com/ctapisab/sap-tech-bytes/blob/2021-09-01-btp-cli-installation/getbtpcli#L61

I hope it helps someone with the same error.

Best regards!
qmacro
Developer Advocate
Developer Advocate

Hey Christian, thanks for the wonderful comment!

That's because I use the "proper" grep from GNU, not the built-in from macOS:

get_version() {

# Determine the version (uses the proper grep, from GNU)

local file=$1
"$file" --version 2> /dev/null | grep -P -o '(?<=v)\d+\.\d+\.\d+'

}

It's absolutely super you bring this up, I was hoping for someone to try it out beyond the context of this blog post (i.e. beyond the modern Bash shell that's available in App Studio), so we can talk about running it in different environments. That is seriously one of my favourite features of the Business Application Studio, i.e. that everyone can access and enjoy a modern, standard and consistent shell environment in the terminal. That, and that it's available in a couple of clicks.

I did consider working around the shortcomings of the macOS built-in grep but at the end of the day, in this container and VM based world, it's more likely that the GNU standard is available than an older BSD flavour will be. Bash and coreutils are available everywhere.

Your solution to use perl is great, thank you for showing that! Also, thanks for forking and changing - that has already made my morning, and it's not even 7am 🙂 !

In addition, some folks on macOS will be stuck with an older version of Bash; macOS has been running a very old (14 years!) and out of date version (3.2.57) for a while, and have now switched to zsh as the default shell. This may show itself through an error with the script early on:

getbtpcli: line 9: ${PLATFORM,,}-amd64: bad substitution

For those curious, this is because the double-comma part of the parameter expansion ${PLATFORM,,} is a feature that the old version 3 Bash doesn't support.

My friend and developer advocate colleague sygyzmundovych already encountered this and let me know, which I thought was wonderful and a similarly great conversation starter.

Anyway, for those encountering these issues, I'm wondering if it might be best to use the issues feature of the SAP-samples/sap-tech-bytes repo itself? 

I've created a couple of issues, with solutions - see https://github.com/SAP-samples/sap-tech-bytes/issues.

What do you think, ctapisab and sygyzmundovych ?

Mattias
Active Participant
Works brilliantly on Ubuntu running under "Linux Subsystem", nothing to report.

Great blog
qmacro
Developer Advocate
Developer Advocate
0 Kudos
Thank you Mattias, that's great to hear. I was hoping that it would.
christian102094
Participant
Thanks dj.adams.sap  for the elaborated revision of the error.

Totally agree with logging these as GitHub issues. I will be doing it more and encouraging my colleagues to do so.
fabianorosa
Participant
Hi DJ Adams,

Very helpful blog post! As a suggestion, maybe you can make it available on Homebrew.

Cheers!

Fabiano Rosa
qmacro
Developer Advocate
Developer Advocate
Hi there Fabiano, thanks for your comment! The suggestion to consider homebrew is an interesting one, but one that ultimately I will thank you for and decline, for a few reasons:

  • that's only a single-platform solution for installs (macOS only)

  • the main idea of the script is for instructive purposes; adding it as a package to install will cloud that idea, making the most important part, the source code, less relevant

  • I'd like to encourage others to look at the source code and possibly contribute

  • the current method of install, via a simple curl command, follows a well-known simple install process


Hope that's ok with you! 🙂