<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gianluigi Disconzi</title>
    <description>The latest articles on DEV Community by Gianluigi Disconzi (@qword).</description>
    <link>https://dev.to/qword</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F261376%2Fbc24778b-5070-4509-b51e-3d96331b9679.jpeg</url>
      <title>DEV Community: Gianluigi Disconzi</title>
      <link>https://dev.to/qword</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/qword"/>
    <language>en</language>
    <item>
      <title>Configure Path variable in Powershell</title>
      <dc:creator>Gianluigi Disconzi</dc:creator>
      <pubDate>Wed, 04 Dec 2019 14:35:48 +0000</pubDate>
      <link>https://dev.to/qword/configure-path-variable-in-powershell-1g8o</link>
      <guid>https://dev.to/qword/configure-path-variable-in-powershell-1g8o</guid>
      <description>&lt;p&gt;Scenario: for whatever reason you have to develop on a Windows machine and you're not an administrator. Your company enforces the same old Java version on all machines, but you want to try out a more recent one.&lt;br&gt;
After you download a JDK binary distribution in a folder of your choice, it's really easy to set up your IDE to work with that, but what if you want to run Java from Powershell?&lt;br&gt;
Typically your machine will be set up with a system Path variable which points to the old Java version, and that cannot be changed. You try to change the Path in your user variables adding the location to your brand newly downloaded JDK. Hooray right?&lt;/p&gt;

&lt;p&gt;Well... no 😥&lt;/p&gt;

&lt;p&gt;It turns out that user Paths are postponed to system Paths, and when looking for an executable Windows picks the first match.&lt;/p&gt;

&lt;p&gt;Luckily for us, it turns out there's a workaround for that! Similarly to bash with its &lt;code&gt;.bashrc&lt;/code&gt; file, Powershell supports init scripts.&lt;br&gt;
To create an init script, run this command from Powershell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nf"&gt;New-Item&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$profile&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Force&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Go to your Documents folder, you'll find a new &lt;code&gt;WindowsPowerShell&lt;/code&gt; subfolder which contains a Powershell script named &lt;code&gt;Microsoft.PowerShell_profile.ps1&lt;/code&gt;. Edit that file and add a line like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;Path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"C:\Users\my-user-name\apps\my-jdk-folder\bin;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;Env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;Path&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Save and open a new Powershell instance: the script will run automatically when a new shell instance is created. Now you can see the new Path variable with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nf"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;Path&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>powershell</category>
      <category>windows</category>
      <category>java</category>
    </item>
  </channel>
</rss>
