Permission denied error when trying to install Kirby CLI

Following the installation guide on github.com/getkirby/cli
I fail at the first step. This is what is returned.

composer global require getkirby/cli
Changed current directory to /Users/andy/.composer

In RequireCommand.php line 143:
                                                                                
  file_put_contents(./composer.json): Failed to open stream: Permission denied

Any advice welcome.
Andy

Is there already a .composer.json directory in that path? If so, what are the permissions for that folder?

There is a .composer directory.

drwxr-xr-x     5 root  staff      160 Jan 26  2024 .composer

The files in the .composer directory are:

drwxr-xr-x   5 root  staff   160 Jan 26  2024 .
drwxr-x---+ 48 andy  staff  1536 Oct 23 10:46 ..
-rw-r--r--   1 root  staff    13 Jan 26  2024 .htaccess
-rw-r--r--   1 root  staff   799 Nov 30  2023 keys.dev.pub
-rw-r--r--   1 root  staff   799 Nov 30  2023 keys.tags.pub

Thanks

I changed the permissions on the .composer directory to Read Write.
I created a .bash_profile file in the same directory and added the following, as per the guide.

export PATH=~/.composer/vendor/bin:$PATH

Tried, once more with

composer global require getkirby/cli

Successfully installed.

Did it work?

No, but I’m getting closer.

Now getting this

zsh: command not found: kirby

Did you restart the terminal window or source the file?

Earlier I restarted the computer, but it still was not working.

So I sourced the file (which I knew nothing about) as you advised with

source ~/.bash_profile

Now working. Thank you for taking the time to help.

Andy