Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What you need to know about the $ENVIRONMENT

What you need to know about the $ENVIRONMENT

When running production things we're pretty much inevitably dealing with the environment. It is pretty straightforward but has some quirks. Here are some of the lessons I have learned.

Recording

Björn Andersson

February 25, 2016
Tweet

More Decks by Björn Andersson

Other Decks in Programming

Transcript

  1. @gaqzi how do you set one then? > name="Björn" >

    echo Hello, $name # => Hello, Björn
  2. @gaqzi how do you set one then? > name="Björn" >

    echo Hello, $name # => Hello, Björn > env | grep name # => <empty>
  3. @gaqzi how do you set one then? > name="Björn" >

    echo Hello, $name # => Hello, Björn > env | grep name # => <empty> > export name
  4. @gaqzi how do you set one then? > name="Björn" >

    echo Hello, $name # => Hello, Björn > env | grep name # => <empty> > export name > env | grep name # => name=Björn
  5. @gaqzi so it’s all safe then? > sleep 1000 &


    [1] 18270 > ps -E 18270
 PID TTY TIME CMD
 18270 ttys001 0:00.00 sleep 1000 PATH=/Users/ba/.rbenv/shims:/ Users/ba/.rbenv/bin:/Users/ba/.pyenv/shims:/Users/ba/Library/Haskell/ bin:/Users/ba/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/ bin:/usr/local/mysql/bin name=Björn [… snip …]
  6. @gaqzi variables set by the system • When your shell

    is loaded as a login shell it’ll:
  7. @gaqzi variables set by the system • When your shell

    is loaded as a login shell it’ll: • Load system level startup scripts (/etc/pro fi le.d/*.sh)
  8. @gaqzi variables set by the system • When your shell

    is loaded as a login shell it’ll: • Load system level startup scripts (/etc/pro fi les (.bashrc, .zshrc, etc…)
  9. @gaqzi how does rbenv, pyenv, and the like work? •

    It’s all about your $PATH • Search paths separated by colons (/Users/ba/.rbenv/shims:/usr/ local/bin:/usr/bin:/bin)
  10. @gaqzi how does rbenv, pyenv, and the like work? •

    It’s all about your $PATH • Search paths separated by colons (/Users/ba/.rbenv/shims:/usr/ local/bin:/usr/bin:/bin) • Whatever is fi rst (left to right) in your path gets picked
  11. @gaqzi . ├── User s │ └── b a │

    └── .rben v │ └── shim s │ └── rub y ├── bi n │ └── emac s └── us r ├── bi n │ └── n c └── loca l └── bi n ├── rub y └── vim ->/bin/emacs export PATH=/bin:/usr/bin:/usr/local/bin:/Users/ba/.rbenv/shims
  12. @gaqzi . ├── User s │ └── b a │

    └── .rben v │ └── shim s │ └── rub y ├── bi n │ └── emac s └── us r ├── bi n │ └── n c └── loca l └── bi n ├── rub y └── vim ->/bin/emacs export PATH=/bin:/usr/bin:/usr/local/bin:/Users/ba/.rbenv/shims
  13. @gaqzi . ├── User s │ └── b a │

    └── .rben v │ └── shim s │ └── rub y ├── bi n │ └── emac s └── us r ├── bi n │ └── n c └── loca l └── bi n ├── rub y └── vim ->/bin/emacs export PATH=/bin:/usr/bin:/usr/local/bin:/Users/ba/.rbenv/shims
  14. @gaqzi debugging • init scripts not running as login shell,

    default path (/bin:/sbin) • some programs don’t inherit environment even if it’s there for security (nginx)
  15. @gaqzi debugging • init scripts not running as login shell,

    default path (/bin:/sbin) • some programs don’t inherit environment even if it’s there for security (nginx) • lots of wrapper scripts to set the environment (/etc/defaults or /etc/ syscon fi g scripts)
  16. @gaqzi debugging wkhtmltopdf • nginx + rails + passenger after

    upgrade to Ruby 2.1.3 • picked up system ruby which was 2.0.0 (/usr/bin/ruby)
  17. @gaqzi debugging wkhtmltopdf • nginx + rails + passenger after

    upgrade to Ruby 2.1.3 • picked up system ruby which was 2.0.0 (/usr/bin/ruby) • set a $PATH in nginx (env PATH=/Users/ba/.rbenv/shims:/usr/…;)
  18. @gaqzi debugging wkhtmltopdf • nginx + rails + passenger after

    upgrade to Ruby 2.1.3 • picked up system ruby which was 2.0.0 (/usr/bin/ruby) • set a $PATH in nginx (env PATH=/Users/ba/.rbenv/shims:/usr/…;) • after that whtmltopdf picked up a .ruby-version fi le from $HOME/.ruby-version, pointing to 2.0.0 as well 😓
  19. @gaqzi debugging wkhtmltopdf • nginx + rails + passenger after

    upgrade to Ruby 2.1.3 • picked up system ruby which was 2.0.0 (/usr/bin/ruby) • set a $PATH in nginx (env PATH=/Users/ba/.rbenv/shims:/usr/…;) • after that whtmltopdf picked up a .ruby-version f i
  20. @gaqzi debugging ASCII encoding • python 3.4 can’t write UTF-8

    encoded strings to STDOUT, 
 because STDOUT is for some reason in ASCII
  21. @gaqzi debugging RubyMine • RubyMine is running and saying that

    /Users/ba/.rbenv/shims/ruby doesn’t have ruby
  22. @gaqzi debugging RubyMine • RubyMine is running and saying that

    /Users/ba/.rbenv/shims/ruby doesn’t have ruby • echo $PATH shows “/usr/local/opt/rbenv/shims:…”
  23. @gaqzi debugging RubyMine • RubyMine is running and saying that

    /Users/ba/.rbenv/shims/ruby doesn’t have ruby • echo $PATH shows “/usr/local/opt/rbenv/shims:…” • ~/.rbenv/ is basically empty, removed it and it worked
  24. @gaqzi pulling together • check your $PATH so you know

    where you’re going • env, because a snapshot lasts
  25. @gaqzi pulling together • check your $PATH so you know

    where you’re going • env, because a snapshot lasts • $LANG, $LC_*, $TZ, $PATH, and others can affect you various weird and interesting ways
  26. @gaqzi pulling together • check your $PATH so you know

    where you’re going • env, because a snapshot lasts • $LANG, $LC_*, $TZ, $PATH, and others can affect you various weird and interesting ways • your basic unix skills pay off. learn the basics of how your computer work and your life will be easier