title: Changing current directory
body: <p>I have written a Ruby script to install Apache Tomcat on my local machine. When I run the script I am not able to change the current directory to one I want:</p>
  
  <pre><code>cmd = "mkdir /usr/java"
  system(cmd)
  
  cmd = "cp /home/user/Downloads/file.txt   /usr/java/"
  system(cmd)
  
  sleep(2)      
  
  cmd = "cd /usr/java/"
  system(cmd)
  </code></pre>
  
  <p>In the above code the <code>mkdir</code> and <code>cp</code> commands work fine, but the problem is with the <code>cd</code> command. After it my current directory is still <code>/</code>, i.e. the parent of <code>/usr</code> directory.</p>
  
  <p><strong>Update:</strong> Using <code>Dir.chdir()</code> worked, but I am facing one more problem in setting the <code>JAVA_HOME</code> and <code>PATH</code> variables. My code is:</p>
  
  <pre><code>cmd = "JAVA_HOME=/usr/java/jdk1.7.0_05"
  system(cmd)
  cmd = "export JAVA_HOME"
  system(cmd)
  cmd = "PATH=$JAVA_HOME/bin:$PATH"
  system(cmd)
  cmd = "export PATH"
  system(cmd)
  </code></pre>