zig icon indicating copy to clipboard operation
zig copied to clipboard

clarify error: "unable to find zig installation directory: FileNotFound"

Open godalming123 opened this issue 2 years ago • 5 comments

Zig Version

0.12.0-dev.494+a8d2ed806

Steps to Reproduce and Observed Output

  1. Download the latest nightly .tar.xz file binary for linux
  2. Copy the zig binary from that tarball to /bin/
  3. Attempt to run it in a terminal
  4. Witness the errror

Expected Output

The error should describe what you need to put where, something like: "Please place the lib directory from the zig extracted source code into /bin" (Or replace /bin with wherever that directory is recommended to go to fix the error - I could make it work by copying all the files in it to /lib)

godalming123 avatar Sep 23 '23 15:09 godalming123

The following worked for me OK:

  1. Unpack the tar file somewhere.
  2. symlink the zig executable to a bin/ directory in my path.

slonik-az avatar Sep 23 '23 16:09 slonik-az

I can get zig to work fine, it's just that this is not the best error message for new users

godalming123 avatar Sep 23 '23 17:09 godalming123

The relevant information is in the GitHub readme:

A Zig installation is composed of two things:

  1. The Zig executable
  2. The lib/ directory

At runtime, the executable searches up the file system for the lib/ directory, relative to itself:

  • lib/
  • lib/zig/
  • ../lib/
  • ../lib/zig/
  • (and so on)

In other words, you can unpack a release of Zig anywhere, and then begin using it immediately. There is no need to install it globally, although this mechanism supports that use case too (i.e. /usr/bin/zig and /usr/lib/zig/).

The 'Getting started' section of the website doesn't have the same level of detail:

Direct download

This is the most straight-forward way of obtaining Zig: grab a Zig bundle for your platform from the Downloads page, extract it in a directory and add it to your PATH to be able to call zig from any location.

squeek502 avatar Sep 24 '23 04:09 squeek502

Also ran into this FileNotFound error when building from source and then copying the binary to my ~/bin folder on macOS.

This produces stage3/bin/zig which is the Zig compiler built by itself. https://github.com/ziglang/zig/wiki/Building-Zig-From-Source#for-macos--homebrew

Copying the stage3/lib folder over got it working. Agreed that the error message could be better. Thanks.

nathany avatar Sep 28 '23 05:09 nathany

Same as @nathany here, after building from source on Debian and using /usr/local instead of ~/, I had to sudo cp -ar build/stage3/lib/zig /usr/local/lib/ as well as sudo cp -a build/stage3/bin/zig /usr/local/bin/. I added some language in the "build from source" wiki page to describe the need to copy the lib folder as well as the zig compiler binary onto your path.

timblaktu avatar May 09 '24 23:05 timblaktu

Is there a reason we couldn't add a more descriptive error here? Pretty simple once you figure it out, but comes up even when you're working from pre-built -- I unzipped and accidentally separated the binaries and lib. Yes, it's in the documentation, but could save a lot of people 20 minutes to have a more descriptive error.

tanner49 avatar Oct 15 '24 20:10 tanner49