Search code examples
amazon-web-servicesunixubuntu-18.04

command 'sam' not found using sudo


I have installed sam using following

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-linux.html

I can run following

sam build

But not

sudo sam build 
which gives me => sudo: sam: command not found

Further going I have found that I need to sudo permission to sudo as follows.

sudo env "PATH=/home/linuxbrew/.linuxbrew/bin/sam" sam

Is the above correct? I haven't run this command and not sure if it is proper.

This is what I have run.

test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile

Solution

  • You can try this:
    In a normal terminal (normal user):

    which sam
    

    This will give you the location, where sam is installed, let's say /somewhere/bin/sam.

    Then: try:

    sudo /somewhere/bin/sam build