# CRYSTAL\_PATH not always includes the default libraries paths if user specify $CRYSTAL\_PATH manually

**URL:** <https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908>\
**Category:** Help & Support\
**Created:** [September 3, 2022, 7:30am UTC](https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908 "2022-09-03T07:30:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [September 3, 2022, 7:30am UTC](https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908/1 "2022-09-03T07:30:31Z")

</div>

I ask this question because this behavior not same as Ruby $RUBYLIB.

Following is my default env when not define $CRYSTAL\_PATH.

```nohighlight
 ╰─ $ cr env CRYSTAL_PATH
lib:/home/zw963/Crystal/bin/../share/crystal/src

```

Then when i specify $CRYSTAL\_PATH manually like following, i even can’t run a hello world successful.

```nohighlight
 ╰─ $ export CRYSTAL_PATH=~/Dropbox/common/crystal/lib

 ╰─ $ cr env CRYSTAL_PATH
/home/zw963/Dropbox/common/crystal/lib

 ╰─ $ cr 1.cr  
Showing last frame. Use --error-trace for full trace.

In 1.cr:1:1

 1 | puts "hello world"
     ^
Error: can't find file 'prelude'

If you're trying to require a shard:
- Did you remember to run `shards install`?
- Did you make sure you're running the compiler in the same directory as your shard.yml?

```

This behavior is unexpected for a user come from Ruby, because, when add paths into $RUBYLIB,  
those paths will prepend into $LOAD\_PATH array, that is, the default $LOAD\_PATH always exists for avoid even a very simple hello world is broken.

```nohighlight
 ╰─ $ ruby -e 'puts $LOAD_PATH'
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/site_ruby/3.1.0
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/site_ruby/3.1.0/x86_64-linux
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/site_ruby
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/vendor_ruby/3.1.0
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/vendor_ruby/3.1.0/x86_64-linux
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/vendor_ruby
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/3.1.0
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/3.1.0/x86_64-linux

 ╰─ $ RUBYLIB=/home/zw963/ruby/lib ruby -e 'puts $LOAD_PATH'
/home/zw963/ruby/lib
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/site_ruby/3.1.0
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/site_ruby/3.1.0/x86_64-linux
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/site_ruby
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/vendor_ruby/3.1.0
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/vendor_ruby/3.1.0/x86_64-linux
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/vendor_ruby
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/3.1.0
/home/zw963/.rvm/rubies/ruby-3.1.0/lib/ruby/3.1.0/x86_64-linux

```

I’m throwing this question just want to know if this behavior is intentional, for now, the workaround is:

```nohighlight
export CRYSTAL_PATH=~/Dropbox/common/crystal/lib:lib:"$(dirname `which crystal`)/../share/crystal/src"

```

But, i consider the `lib:"$(dirname `which crystal`)/../share/crystal/src` part is really not necessary.

Or, am I missing some environment variable that can just prepend path into CRYSTAL\_PATH instead of override?

Thank you.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 3, 2022, 2:07pm UTC](https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908/2 "2022-09-03T14:07:25Z")

</div>

> [@zw963](#):
>
> Or, am I missing some environment variable that can just prepend path into CRYSTAL\_PATH instead of override?

~~Is there a reason you can’t just treat it as like `$PATH` and do like `export CRYSTAL_PATH="/home/zw963/Dropbox/common/crystal/lib:$CRYSTAL_PATH"`?~~

EDIT: NVM, issue is the env var is defined via the wrapper script so that just ends up overriding it anyway.

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [September 3, 2022, 2:11pm UTC](https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908/3 "2022-09-03T14:11:43Z")

</div>

Hi, AFAIK, use like this not work too, because the $CRYSTAL\_PATH is unset by default.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 3, 2022, 2:14pm UTC](https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908/4 "2022-09-03T14:14:19Z")

</div>

`export CRYSTAL_PATH="/some/path:$(crystal env CRYSTAL_PATH)"` This should so it. Prepend your custom path(s) before the default path(s).

```auto
$ crystal env CRYSTAL_PATH
/some/path:lib:/usr/lib/crystal

```

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [September 3, 2022, 2:19pm UTC](https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908/5 "2022-09-03T14:19:36Z")

</div>

> `export CRYSTAL_PATH="/some/path:$(crystal env CRYSTAL_PATH)"`

This usage is really cool, I didn’t even think of it.

If the the behavior of current CRYSTAL\_PATH behavior correct and expected, this is probably the best solution.

Thank you.

Although, the difference with $RUBYLIB probably confuse Rubyist.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [September 5, 2022, 7:57am UTC](https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908/6 "2022-09-05T07:57:31Z")

</div>

> [@zw963](#):
>
> If the the behavior of current CRYSTAL\_PATH behavior correct and expected, this is probably the best solution

Yes it’s intended that way and documented accordingly. It’s not really designed for end users who want to pull in a custom source directory. It’s mostly used for system configuration (for example within wrapper scripts) and for that it must override any built-in configuration.

What’s your use case for adding another code location? Perhaps we can find an easier solution for that.

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [September 5, 2022, 11:16am UTC](https://forum.crystal-lang.org/t/crystal-path-not-always-includes-the-default-libraries-paths-if-user-specify-crystal-path-manually/4908/7 "2022-09-05T11:16:34Z")

</div>

My use case is, i save [this](https://forum.crystal-lang.org/t/print-out-the-instance-methods-defined-class-or-the-path-where-the-current-class-is/4771/2) really useful snippets write by @asterite to, e.g. `~/Dropbox/common/crystal/lib/meta.cr`, then prepend this folder into $CRYSTAL\_PATH.

now, i can use those methods defined in meta.cr, like this:

```crystal
require "meta"

pp! "hello".methods
pp! String.class_methods

```
