Slide 1

Slide 1 text

@gaqzi what you need to know about the $ENVIRONMENT Björn Andersson

Slide 2

Slide 2 text

@gaqzi Björn 
 code monkey, devops, and 
 loud mouth pythonista

Slide 3

Slide 3 text

@gaqzi

Slide 4

Slide 4 text

@gaqzi

Slide 5

Slide 5 text

@gaqzi what is an environment variable?

Slide 6

Slide 6 text

@gaqzi how do you set one then?

Slide 7

Slide 7 text

@gaqzi how do you set one then?

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

@gaqzi > AWS_ACCESS_TOKEN=deadbeef \ rake aws:s3:create_bucket[rdrc] what does this do?

Slide 14

Slide 14 text

@gaqzi so it’s all safe then?

Slide 15

Slide 15 text

@gaqzi

Slide 16

Slide 16 text

@gaqzi

Slide 17

Slide 17 text

@gaqzi

Slide 18

Slide 18 text

@gaqzi

Slide 19

Slide 19 text

@gaqzi so it’s all safe then?

Slide 20

Slide 20 text

@gaqzi so it’s all safe then? > sleep 1000 &
 [1] 18270

Slide 21

Slide 21 text

@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 …]

Slide 22

Slide 22 text

@gaqzi variables set by the system

Slide 23

Slide 23 text

@gaqzi variables set by the system

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

@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)

Slide 26

Slide 26 text

@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…)

Slide 27

Slide 27 text

@gaqzi how does rbenv, pyenv, and the like work?

Slide 28

Slide 28 text

@gaqzi how does rbenv, pyenv, and the like work? • It’s all about your $PATH

Slide 29

Slide 29 text

@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)

Slide 30

Slide 30 text

@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

Slide 31

Slide 31 text

@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

Slide 32

Slide 32 text

@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

Slide 33

Slide 33 text

@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

Slide 34

Slide 34 text

@gaqzi debugging

Slide 35

Slide 35 text

@gaqzi

Slide 36

Slide 36 text

@gaqzi

Slide 37

Slide 37 text

@gaqzi

Slide 38

Slide 38 text

@gaqzi debugging

Slide 39

Slide 39 text

@gaqzi debugging • init scripts not running as login shell, default path (/bin:/sbin)

Slide 40

Slide 40 text

@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)

Slide 41

Slide 41 text

@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)

Slide 42

Slide 42 text

@gaqzi debugging wkhtmltopdf

Slide 43

Slide 43 text

@gaqzi debugging wkhtmltopdf • nginx + rails + passenger after upgrade to Ruby 2.1.3

Slide 44

Slide 44 text

@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)

Slide 45

Slide 45 text

@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/…;)

Slide 46

Slide 46 text

@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 😓

Slide 47

Slide 47 text

@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

Slide 48

Slide 48 text

@gaqzi debugging ASCII encoding

Slide 49

Slide 49 text

@gaqzi debugging ASCII encoding • python 3.4 can’t write UTF-8 encoded strings to STDOUT, 
 because STDOUT is for some reason in ASCII

Slide 50

Slide 50 text

@gaqzi debugging ASCII encoding • python 3.4 can’t write UTF-8 encoded strings to STDOUT, 


Slide 51

Slide 51 text

@gaqzi debugging ASCII encoding • python 3.4 can’t write UTF-8 encoded strings to STDOUT, 


Slide 52

Slide 52 text

@gaqzi debugging ASCII encoding • python 3.4 can’t write UTF-8 encoded strings to STDOUT, 


Slide 53

Slide 53 text

@gaqzi debugging RubyMine

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

@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:…”

Slide 56

Slide 56 text

@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

Slide 57

Slide 57 text

@gaqzi pulling together

Slide 58

Slide 58 text

@gaqzi pulling together

Slide 59

Slide 59 text

@gaqzi pulling together • check your $PATH so you know where you’re going

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

@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

Slide 62

Slide 62 text

@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

Slide 63

Slide 63 text

@gaqzi

Slide 64

Slide 64 text

@gaqzi

Slide 65

Slide 65 text

@gaqzi thanks! [email protected] @gaqzi