Set ~/.cargo to custom path in singularity

I'm unable to set default ~/.cargo path to custom path in singularity that has all my softwares.
could you pls advice?

Bootstrap: docker
From: ubuntu:20.04

%labels
    Maintainer samuel ahuno
    Version v0.0.1

%help
    Singularity for rust and cargo & other bioinformatics softwares

%post
    # Install dependencies
    apt-get update && apt-get install -y \
    python3 python3-pip \
    autoconf \
    automake \
    bzip2 \
    gcc \
    git \
    make \
    wget curl



    ### add rust and cargo
    cd /opt
    curl https://sh.rustup.rs -sSf | sh -s -- -y
    mv $HOME/.cargo /usr/local/.cargo 
    . "/usr/local/.cargo/bash"
    ln -s /usr/local/.cargo/bin/ /usr/local/bin/


    # # Install Oxford Nanopore basecaller Dorado
    cd /opt
    #wget https://cdn.oxfordnanoportal.com/software/analysis/dorado-0.8.1-linux-x64.tar.gz
    #tar -xvzf dorado-0.8.1-linux-x64.tar.gz
    #mv dorado-0.8.1-linux-x64 /usr/local/dorado
    #ln -s /usr/local/dorado/bin/dorado /usr/local/bin/dorado

%environment
    export PATH="/usr/local/bin:$PATH"
    export LISTEN_PORT=12345

%runscript
    echo "This is a Singularity container for rust Cargo"
    exec "$@"

what exactly doesn't work? do you get an error message?

i get fatal error after building singularity image and calling rustc --help

$ singularity exec rust_cargo_install.sif rustc --help
FATAL: "rustc": executable file not found in $PATH

This looks like it could lead to some trouble. I'd instead use the CARGO_HOME and RUSTUP_HOME environment variables during installation to make sure rustup is set up correctly. I.e. replace the above with:

CARGO_HOME="/usr/local/.cargo" RUSTUP_HOME="/usr/local/.rustup" curl https://sh.rustup.rs -sSf | sh -s -- -y

And then make sure to add /usr/local/.cargo/bin to your PATH environment variable.

1 Like

thanks showing cargo home and rustup home during installation. i will default to that.
i also tried moving installation directories and documented results here for anyone who faces similar issue;

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.