Here’s the article:
Can’t Install Solana CLI from Docker on a Mac
As a developer of Anchor, one of the most popular blockchain projects in the space, you’re likely no stranger to working with Docker. In fact, your development environment probably involves a containerized setup for your application and testing environments.
However, when it comes to installing the latest version of Solana CLI (also known as solana-cli), you may encounter an unexpected error while trying to install it from Docker. Specifically, you’re getting an error saying that Solana CLI can’t be installed due to a conflicting environment variable or permission issue.
The Problem
To fix this issue, we need to modify the Dockerfile
for Anchor development to install Solana CLI in a way that resolves these conflicts and allows it to be installed successfully. Here’s what needs to change:
FROM solana-cli:latest
RUN sh -c "curl -sfL > /tmp/solana-cli && \
chmod +x /tmp/solana-cli && \
export PATH=$PATH:/tmp/solana-cli"
What’s Changed
In the modified Dockerfile
, we’ve made two key changes:
- We’re downloading and installing Solana CLI from a CDN instead of using a local copy in the
FROM
instruction.
- We’re using the
RUN
instruction to install Solana CLI by downloading it, making it executable withchmod +x /tmp/solana-cli
, and adding it to the system’s PATH.
Why This Works
By installing Solana CLI from a CDN and then moving it to the system’s PATH, we avoid any conflicts with the Docker image that comes pre-installed with your container. The /tmp
directory is also used as a temporary location to store the installation process, ensuring that the executable is not left behind after the installation.
Getting Back on Track
With these modifications in place, you should now be able to install Solana CLI from Docker without any issues. Make sure to update your Dockerfile
accordingly and run it again to ensure everything is working as expected.
Full Code Example
For reference, here’s the full modified code:
![Solana: Can't install Solana CLI from Docker on a Mac](https://www.abzx.xyz/wp-content/uploads/2025/02/5d4e6476.png)
Use an official Solana image for the anchor app container
FROM solana-cli:latest
Download Solana CLI from a CDN
RUN sh -c "curl -sfL > /tmp/solana-cli && \
chmod +x /tmp/solana-cli && \
export PATH=$PATH:/tmp/solana-cli"
Make Solana CLI executable and add it to the system's PATH
RUN sh -c "curl -sfL > /tmp/solana-cli && \
chmod +x /tmp/solana-cli && \
export PATH=$PATH:/tmp/solana-cli"
By making these changes, you should be able to successfully install Solana CLI from Docker on your Mac. Happy developing!
دیدگاهتان را بنویسید