awscli not in the path on macOS - macos

I have so far tried installed awscli via the commandline and via the interactive installer , using brew and pip however I cannot use the aws command due to path configuration
which aws
/usr/local/bin
But when I try
aws --version I get
/Library/Frameworks/Python.framework/Versions/2.7/bin/aws: No such file or directory
How can I have aws command run from the correct location?
I also tried running aws command from /usr/local/bin but have the same error
I have tried this in a new shell and this is aws cli v2
also tried this
type aws
aws is hashed (/Library/Frameworks/Python.framework/Versions/2.7/bin/aws)

Same issue:
$ /usr/local/bin/aws --version
aws-cli/2.0.23 Python/3.7.4 Darwin/19.4.0 botocore/2.0.0dev27
Solution:
export PATH=$PATH:/usr/local/bin/aws

If having issues updating/upgrading the awscliv1 to v2.
Take the following step:
rm -rf /bin/aws
curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install -i /usr/local/aws -b /bin
export the PATH to the bin/aws previously remove
export PATH=$PATH:/usr/local/bin/aws

Related

No such file or directory when executing command via docker run -it

I have this Dockerfile (steps based on installation guide from AWS)
FROM amazon/aws-cli:latest
RUN yum install python37 -y
RUN curl -O https://bootstrap.pypa.io/get-pip.py
RUN python3 get-pip.py --user
RUN pip3 install awsebcli --upgrade --user
RUN echo 'export PATH=~/.local/bin:$PATH' >> ~/.bashrc
RUN source ~/.bashrc
ENTRYPOINT ["/bin/bash"]
When I build the image with docker build -t eb-cli . and then run eb --version inside container docker run -it eb-cli, everything works
bash-4.2# eb --version
EB CLI 3.20.3 (Python 3.7.1)
But, when I run the command directly as docker run -it eb-cli eb --version, it gives me this error
/bin/bash: eb: No such file or directory
I think that is problem with bash profiles, but I can't figure it out.
Your sourced .bashrc would stay in the layer it was sourced, but won't apply to the resulting container. This is actually more thoroughly explained in this answer:
Each command runs a separate sub-shell, so the environment variables are not preserved and .bashrc is not sourced
Source: https://stackoverflow.com/a/55213158/2123530
A solution for you would be to set the PATH in an environment variable of the container, rather, and blank the ENTRYPOINT as set by your base image.
So you could end with an image as simple as:
FROM amazon/aws-cli:latest
ENV PATH="/root/.local/bin:${PATH}"
RUN yum install python37 -y \
&& pip3 install awsebcli
ENTRYPOINT []
With this Dockerfile, here is the resulting build and run:
$ docker build . -t eb-cli -q
sha256:49c376d98fc2b35cf121b43dbaa96caf9e775b0cd236c1b76932e25c60b231bc
$ docker run eb-cli eb --version
EB CLI 3.20.3 (Python 3.7.1)
Notes:
you can install the really latest version of pip, as you did it, but it is not needed as it is already bundled in the package python37
installing packages for the user, with the --user flag, is a good practice indeed, but since you are running this command as root, there is no real point in doing so, in the end
having the --upgrade flag does not makes much more sense, here, as the package won't be installed beforehand. And upgrading the package would be as simple as rebuilding the image
reducing the number of layer of an image by reducing the number of RUN in your Dockerfile is an advisable practice that you can find in the best practice

python3 command not found for EC2 non root user

I want to know how to add a python3.7 path for non root unix user on EC2.
I created an EC2 instance and logged in via ssh. And I created a user called jpx by adduser jpx. So my home directory has ec2-user and jpx sub directories.
As a root user, I installed python3.7, following this tutorial. Basically, I followed these steps:
yum install gcc openssl-devel bzip2-devel libffi-devel
cd /opt
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
sudo tar xzf Python-3.7.9.tgz
cd Python-3.7.9
sudo ./configure --enable-optimizations
sudo make altinstall
sudo rm /usr/src/Python-3.7.9.tgz
As a result, my python3.7 was installed at /usr/local/bin/python3.7.
Questions:
As a root user, I was able to add /usr/local/bin/ to my PATH in the bash_profile. So now the command python3.7 works. But I want to set the command python3 instead of python3.7, so that I can run python3 app.py instead of python3.7 app.py. How can I do this?
As a user jpx, I cannot run the command python3.7. It returns bash: python3.7: command not found. When I print echo $PATH, indeed its' /sbin:/bin:/usr/sbin:/usr/bin and the python3.7 path is not included. As a linux beginner I want to understand why this happens. And what is the solution? Not only python3, but also I need to install pip.
Thank you for your help!
You can link the executable file
cd /usr/local/bin
ln -s python3.7 python3
Add the path to the user home .bashrc
vi /home/jpx/.bashrc
Add the following line
export PATH="/usr/local/bin:$PATH"
Logout and login again

Cannot build dockerfile with sdkman

I am entirely new to the concept of dockers. I am creating the following Dockerfile as an exercise.
FROM ubuntu:latest
MAINTAINER kesarling
RUN apt update && apt upgrade -y
RUN apt install nginx curl zip unzip -y
RUN apt install openjdk-14-jdk python3 python3-doc clang golang-go gcc g++ -y
RUN curl -s "https://get.sdkman.io" | bash
RUN bash /root/.sdkman/bin/sdkman-init.sh
RUN sdk version
RUN yes | bash -c 'sdk install kotlin'
CMD [ "echo","The development environment has now been fully setup with C, C++, JAVA, Python3, Go and Kotlin" ]
I am using SDKMAN! to install Kotlin. The problem initially was that instead of using RUN bash /root/.sdkman/bin/sdkman-init.sh, I was using RUN source /root/.sdkman/bin/sdkman-init.sh. However, it gave the error saying source not found. So, I tried using RUN . /root/.sdkman/bin/sdkman-init.sh, and it did not work. However, RUN bash /root/.sdkman/bin/sdkman-init.sh seems to work, as in does not give any error and tries to run the next command. However, the docker then gives error saying sdk: not found
Where am I going wrong?
It should be noted that these steps worked like charm for my host distribution (The one on which I'm running docker) which is Pop!_OS 20.04
Actually the script /root/.sdkman/bin/sdkman-init.sh sources the sdk
source is a built-in to bash rather than a binary somewhere on the filesystem.
source command executes the file in the current shell.
Each RUN instruction will execute any commands in a new layer on top of the current image and commit the results.
The resulting committed image will be used for the next step in the Dockerfile.
Try this:
FROM ubuntu:latest
MAINTAINER kesarling
RUN apt update && apt upgrade -y
RUN apt install nginx curl zip unzip -y
RUN apt install openjdk-14-jdk python3 python3-doc clang golang-go gcc g++ -y
RUN curl -s "https://get.sdkman.io" | bash
RUN /bin/bash -c "source /root/.sdkman/bin/sdkman-init.sh; sdk version; sdk install kotlin"
CMD [ "echo","The development environment has now been fully setup with C, C++, JAVA, Python3, Go and Kotlin" ]
SDKMAN in Ubuntu Dockerfile
tl;dr
the sdk command is not a binary but a bash script loaded into memory
Shell sessions are a "process", which means environment variables and declared shell function only exist for the duration that shell session exists; which lasts only as long as the RUN command.
Manually tweak your PATH
RUN apt-get update && apt-get install curl bash unzip zip -y
RUN curl -s "https://get.sdkman.io" | bash
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" \
&& sdk install java 8.0.275-amzn \
&& sdk install sbt 1.4.2 \
&& sdk install scala 2.12.12
ENV PATH=/root/.sdkman/candidates/java/current/bin:$PATH
ENV PATH=/root/.sdkman/candidates/scala/current/bin:$PATH
ENV PATH=/root/.sdkman/candidates/sbt/current/bin:$PATH
Full Version
Oh wow this was a journey to figure out. Below each line is commented as to why certain commands are run.
I learnt a lot about how unix works and how sdkman works and how docker works and why the intersection of the three give very unusual behaviour.
# I am using a multi-stage build so I am just copying the built artifacts
# from this stage to keep final image small.
FROM ubuntu:latest as ScalaBuild
# Switch from `sh -c` to `bash -c` as the shell behind a `RUN` command.
SHELL ["/bin/bash", "-c"]
# Usual updates
RUN apt-get update && apt-get upgrade -y
# Dependencies for sdkman installation
RUN apt-get install curl bash unzip zip -y
#Install sdkman
RUN curl -s "https://get.sdkman.io" | bash
# FUN FACTS:
# 1) the `sdk` command is not a binary but a bash script loaded into memory
# 2) Shell sessions are a "process", which means environment variables
# and declared shell function only exist for
# the duration that shell session exists
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" \
&& sdk install java 8.0.275-amzn \
&& sdk install sbt 1.4.2 \
&& sdk install scala 2.12.12
# Once the real binaries exist these are
# the symlinked paths that need to exist on PATH
ENV PATH=/root/.sdkman/candidates/java/current/bin:$PATH
ENV PATH=/root/.sdkman/candidates/scala/current/bin:$PATH
ENV PATH=/root/.sdkman/candidates/sbt/current/bin:$PATH
# This is specific to running a minimal empty Scala project and packaging it
RUN touch build.sbt
RUN sbt compile
RUN sbt package
FROM alpine AS production
# setup production environment image here
COPY --from=ScalaBuild /root/target/scala-2.12/ $INSTALL_PATH
ENTRYPOINT ["java", "-cp", "$INSTALL_PATH", "your.main.classfile"]
Generally you want to avoid using "version manager" type tools in Docker; it's better to install a specific version of the compiler or runtime you need.
In the case of Kotlin, it's a JVM application distributed as a zip file so it should be fairly easy to install:
FROM openjdk:15-slim
ARG KOTLIN_VERSION=1.3.72
# Get OS-level updates:
RUN apt-get update \
&& apt-get install --no-install-recommends --assume-yes \
curl \
unzip
# and if you need C/Python dependencies, those too
# Download and unpack Kotlin
RUN cd /opt \
&& curl -LO https://github.com/JetBrains/kotlin/releases/download/v${KOTLIN_VERSION}/kotlin-compiler-${KOTLIN_VERSION}.zip \
&& unzip kotlin-compiler-${KOTLIN_VERSION}.zip \
&& rm kotlin-compiler-${KOTLIN_VERSION}.zip
# Add its directory to $PATH
ENV PATH=/opt/kotlinc/bin:$PATH
The real problem with version managers is that they heavily depend on the tool setting environment variables. As #JeevanRao notes in their answer, each Dockerfile RUN command runs in a separate shell in a separate container, and any environment variable settings within that command get lost for the next command.
# Does absolutely nothing: environment variables do not stay set
RUN . /root/.sdkman/bin/sdkman-init.sh
Since an image generally contains only one application and its runtime, you don't need the ability to change which version of the runtime or compiler you're using. My Dockerfile example passes it as an ARG, so you can change it in the Dockerfile or pass a docker build --build-arg KOTLIN_VERSION=... option to use a different version.

Unusual installation of `aws` cli

I am using "MacOS High Sierra".
I installed the aws cli tool a long time ago, don't remember how I installed it.
The installation is a little unusual.
I can run aws from any folder, this is working
$ aws --version
aws-cli/1.11.121 Python/2.7.13 Darwin/17.4.0 botocore/1.7.12
However running
$ which aws
this returns nothing.
I thought it might be an alias, but running
$ alias | grep aws
This also returns nothing.
Its not installed with homebrew either
$ brew list | grep aws
The reason why this is a problem, because there have now been a few cli programs I have ran (Including "AWS Sam" and a build script from my work) which are complaining because aws is not in the path.
I would much rather have a "regular installation" of the aws cli, where I put the executable in some bin folder and then put it in the environment path.
But instead its using some "magic" which I am unfamiliar with. And not even AWS owns tools ("AWS Sam") seem to like the way its installed.
Any advice would be appreciated.
I solved the problem by running
$ pip uninstall awscli
$ brew upgrade
$ brew install awscli
Now I get this result
$ which aws
/usr/local/bin/aws
"AWS Sam" and the other build script I use at work are now working.

Synapse Home server(Matrix) not running

I have installed synapse using the following commands:
link: https://github.com/matrix-org/synapse
Installing prerequisites on Mac OS X:
xcode-select --install
sudo easy_install pip
sudo pip install virtualenv
brew install pkg-config libffi
To install the synapse homeserver run:
virtualenv -p python2.7 ~/.synapse
source ~/.synapse/bin/activate
pip install --upgrade setuptools
pip install https://github.com/matrix-org/synapse/tarball/master
Generate a configuration file
cd ~/.synapse
python -m synapse.app.homeserver \
--server-name my.domain.name \
--config-path homeserver.yaml \
--generate-config \
--report-stats=yes
To get started, it is easiest to use the command line to register new users:
$ source ~/.synapse/bin/activate
$ synctl start # if not already running
$ register_new_matrix_user -c homeserver.yaml https://localhost:8448
New user localpart: user123
Password:
Confirm password:
Server started successfully, but user registration failed and
i opened "https://localhost:8448" in the browser and i got the following:
Can anybody help to solve this?
Your homeserver is probably not starting correctly. Try to get the JSON response about supported versions by executing following in you shell:
curl https://localhost:8448/_matrix/client/versions -k
This should result in a JSON response listing protocol versions:
{
"versions": [
"r0.0.1",
"r0.1.0",
"r0.2.0"
]
}
If that's not working - to find out the real issue you can try:
Check if it's running at all with sudo service matrix-synapse status
Check the log file at /var/log/matrix-synapse/homeserver.log
I will update the answer, in case you can provide more details.
The web client should be accessible at the following URL:
https://localhost:8448/_matrix/client/
However the documentation states:
(The homeserver runs a web client by default at
https://localhost:8448/, though as of the time of writing it is
somewhat outdated and not really recommended -
https://github.com/matrix-org/synapse/issues/1527).
You should use a client such as the one at https://riot.im/app/

Resources