Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing ARM version for Mac #385

Open
dmitryrn opened this issue Aug 14, 2021 · 10 comments
Open

Installing ARM version for Mac #385

dmitryrn opened this issue Aug 14, 2021 · 10 comments

Comments

@dmitryrn
Copy link

go1.16.7.darwin-arm64 is available here https://golang.org/dl/

But how do I install 1.16.7 darwin arm64 via gvm?

When I do gvm install 1.16.7, it installs darwin/amd64.

@sazzer
Copy link

sazzer commented Sep 25, 2021

In case it helps, I've managed to get it working as follows:

  • Download the ARM64 build
  • Unpack into ~/.gvm/gos/
  • Create a file in ~/.gvm/environments/ - just copy the file for a different version and change the version numbers in it
  • Create an empty directory ~/.gvm/pkgsets/

Having done that, I can now do gvm use <version> and it seems to work fine.

@morganhein
Copy link

morganhein commented Feb 4, 2022

Here's a "less pure" way of using gvm to install/manage go, but less involved:
brew install go && gvm install go1.17.6 && gvm use go1.17.6 --default && brew uninstall go

@dwjohnston
Copy link

dwjohnston commented Mar 3, 2022

Ok, so I got this working for me in the end 2021 MacBook Pro, running MacOS Monterey, M1 Chip. Trying to get gvm to install go1.15.6.

I downloading the binary manually from here:

https://go.dev/dl

I download the darwin-amd64 binary. 👈🧐 More on this in a bit.

First thing to do, is extract the tarball and just run the binary manually, check that it works on your machine.

Now follow sazzers instructions to manually add it to your .gvm folder.

Which binary to use?

So this is where I'm a bit confused. My understanding is that the m1 chip is an ARM64 instruction set, so I'd assumed that was the right on to use. But seems like the AMD64 instruction set is the one to use, is that because rosetta is converting it?

Does anyone want to enlighten me on this?

@septemhill
Copy link

There's another way:

  1. Download the ARM64 build, then install, make the version as default
  2. gvm install go1.1x.x (any version you like), it would build from source
  3. You get a ARM64 build from gvm install

After this, every time you want to install other version from gvm, then it would be built in ARM64

@windyear
Copy link

In case it helps, I've managed to get it working as follows:

  • Download the ARM64 build
  • Unpack into ~/.gvm/gos/
  • Create a file in ~/.gvm/environments/ - just copy the file for a different version and change the version numbers in it
  • Create an empty directory ~/.gvm/pkgsets/

Having done that, I can now do gvm use <version> and it seems to work fine.

In case it helps, I've managed to get it working as follows:

  • Download the ARM64 build
  • Unpack into ~/.gvm/gos/
  • Create a file in ~/.gvm/environments/ - just copy the file for a different version and change the version numbers in it
  • Create an empty directory ~/.gvm/pkgsets/

Having done that, I can now do gvm use <version> and it seems to work fine.

it works! Just replace the verion in the environments.

@MatthewLymer
Copy link

@sazzer Create a file in ~/.gvm/environments/ - just copy the file for a different version and change the version numbers in it

Can you elaborate on this, what's the filename and content?

@soulteary
Copy link

Maybe this will help you: #406
You can install binaries directly without local compilation, which is a waste of time.

@MatthewLymer
Copy link

thanks @soulteary, this works great for me!

@lucianomda
Copy link

There's another way:

  1. Download the ARM64 build, then install, make the version as default
  2. gvm install go1.1x.x (any version you like), it would build from source
  3. You get a ARM64 build from gvm install

After this, every time you want to install other version from gvm, then it would be built in ARM64

This worked fine for me and it's pretty straight forward solution, it only works to install go1.16+ with gvm though (AFAIK there is no support for arm64 for go older versions).

Homebrew installs at this time the latest amd64 version available, so I downloaded the arm64 installer from go official site instead. I executed export GOROOT_BOOTSTRAP=$GOROOT before install any version with gvm, but I do not know if it's required.

@sharathchnandikonda
Copy link

In case it helps, I've managed to get it working as follows:

  • Download the ARM64 build
  • Unpack into ~/.gvm/gos/
  • Create a file in ~/.gvm/environments/ - just copy the file for a different version and change the version numbers in it
  • Create an empty directory ~/.gvm/pkgsets/

Having done that, I can now do gvm use <version> and it seems to work fine.

 #!/bin/zsh

 # Usage: ./gvm-install-mac-version 1.22.2
 # Define the Go version you want to download as the first argument
 VERSION=$1

 # Define the URL for downloading the Go package
 URL="https://go.dev/dl/go${VERSION}.darwin-arm64.tar.gz"

 # Define the download and installation directory
 INSTALL_DIR="$HOME/.gvm/gos"

 # Define the environment directory
 ENV_DIR="$HOME/.gvm/environments"

 # Define the pkgsets directory
 PKGSETS_DIR="$HOME/.gvm/pkgsets"

 # Create the installation directory, environment directory, and pkgsets directory if they do not exist
 mkdir -p "$INSTALL_DIR"
 mkdir -p "$ENV_DIR"
 mkdir -p "$PKGSETS_DIR"

 # Define the path to save the downloaded file
 TAR_FILE="${INSTALL_DIR}/go${VERSION}.darwin-arm64.tar.gz"

 # Download the Go package using curl
 echo "Downloading Go version ${VERSION} from ${URL}..."
 curl -L -o "$TAR_FILE" "$URL"

 # Check if the download was successful
 if [[ $? -ne 0 ]]; then
     echo "Failed to download Go version ${VERSION} from ${URL}"
     exit 1
 fi

 # Unpack the tar.gz file
 echo "Unpacking the Go package..."
 tar -C "$INSTALL_DIR" -xzf "$TAR_FILE"

 # Check if the unpacking was successful
 if [[ $? -ne 0 ]]; then
     echo "Failed to unpack the Go package"
     exit 1
 fi

 # Rename the unpacked directory to the specified version
 GO_DIR="${INSTALL_DIR}/go"
 NEW_GO_DIR="${INSTALL_DIR}/go${VERSION}"

echo "Renaming unpacked directory from go to go${VERSION}..."
 mv "$GO_DIR" "$NEW_GO_DIR"

 # Check if the rename was successful
 if [[ $? -ne 0 ]]; then
     echo "Failed to rename the unpacked directory"
     exit 1
 fi

 # Cleanup the downloaded tar.gz file
 echo "Cleaning up the downloaded file..."
 rm "$TAR_FILE"

 echo "Go version ${VERSION} downloaded, unpacked, and installed in ${NEW_GO_DIR}"

 # Create the environment file in ~/.gvm/environments/go${VERSION}
 ENV_FILE="${ENV_DIR}/go${VERSION}"

 # Define the environment content
 cat << EOF > "$ENV_FILE"
 export GVM_ROOT; GVM_ROOT="$HOME/.gvm"
 export gvm_go_name; gvm_go_name="go${VERSION}"
 export gvm_pkgset_name; gvm_pkgset_name="global"
 export GOROOT; GOROOT="\$GVM_ROOT/gos/go${VERSION}"
 export GOPATH; GOPATH="\$GVM_ROOT/pkgsets/go${VERSION}/global"
 export GVM_OVERLAY_PREFIX; GVM_OVERLAY_PREFIX="\${GVM_ROOT}/pkgsets/go${VERSION}/global/overlay"
 export PATH; PATH="\${GVM_ROOT}/pkgsets/go${VERSION}/global/bin:\${GVM_ROOT}/gos/go${VERSION}/bin:\${GVM_OVERLAY_PREFIX}/bin:\${GVM_ROOT}/bin:\${PATH}"
 export LD_LIBRARY_PATH; LD_LIBRARY_PATH="\${GVM_OVERLAY_PREFIX}/lib:\${LD_LIBRARY_PATH}"
 export DYLD_LIBRARY_PATH; DYLD_LIBRARY_PATH="\${GVM_OVERLAY_PREFIX}/lib:\${DYLD_LIBRARY_PATH}"
 export PKG_CONFIG_PATH; PKG_CONFIG_PATH="\${GVM_OVERLAY_PREFIX}/lib/pkgconfig:\${PKG_CONFIG_PATH}"
 EOF

 echo "Environment file created at ${ENV_FILE} with content:"
 cat "$ENV_FILE"

 # Create the pkgsets directory for the specific Go version
 PKGSET_DIR="${PKGSETS_DIR}/go${VERSION}"

 echo "Creating pkgsets directory at ${PKGSET_DIR}..."
 mkdir -p "$PKGSET_DIR"

 echo "Pkgsets directory created for Go version ${VERSION} at ${PKGSET_DIR}"

This can be put into a script called gvm-install-mac-version and be used like:

chmod +x gvm-install-mac-version
 ./gvm-install-mac-version 1.22.2
gvm list
gvm use go1.22.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants