---
description: How to set up Environment Variables to help with Yubikey, GPG, and ykman.
---

# Environment Variables

These steps explain how to setup helpful <mark style="color:red;">**`Environment Variables`**</mark> that you can use to manage your keys and software.



Launch **Command Prompt** in administrator mode.

{% hint style="info" %}
The <mark style="color:red;">**`Command Prompt`**</mark> -> <mark style="color:red;">**SETX**</mark> command is limited to <mark style="color:red;">**`1024 characters`**</mark>.&#x20;

If you have too many entries in your PATH environment variable, doing the commands below will cut off your paths. It's better to use the <mark style="color:red;">**`Powershell`**</mark> method.\
\
BACKUP FIRST USING REGEDIT.
{% endhint %}





## <mark style="color:red;">❊ Managing Environment Variables</mark>

### <mark style="color:blue;">BACKUP</mark>

Select only one method. It's highly recommended you use the regedit version. You can save the backup.reg file somewhere on your desktop and then execute it by double-clicking if you need to restore your original environment variables.

{% tabs %}
{% tab title="Regedit: 1" %}
```rego
regedit /e "%userprofile%\Desktop\my_user_env_variables.reg" "HKEY_CURRENT_USER\Environment"
```
{% endtab %}

{% tab title="Regedit: 2" %}
```rego
set TODAY=%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%

regedit /e "%CD%\user_env_variables[%TODAY%].reg" "HKEY_CURRENT_USER\Environment"
regedit /e "%CD%\global_env_variables[%TODAY%].reg" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
```
{% endtab %}

{% tab title="Command Prompt" %}
```
setx /m PATH_BK "%PATH%"
```
{% endtab %}
{% endtabs %}





### <mark style="color:blue;">PRINT</mark>

To print all environment variables on new lines:

{% tabs %}
{% tab title="Powershell" %}
```powershell
-----------------------------
List All
-----------------------------

dir e

-----------------------------
List Specific
-----------------------------

Get-ChildItem -Path Env:\gpglong
```
{% endtab %}

{% tab title="Command Prompt" %}
```
echo %PATH:;=&echo.%
```
{% endtab %}
{% endtabs %}





## <mark style="color:red;">❊ Command Prompt -> Set ENV -> Add</mark>

### <mark style="color:blue;">APPLICATIONS</mark>

A list of env variables required for [**Keybase**](https://keybase.io/).

{% tabs %}
{% tab title="Powershell" %}
<pre class="language-powershell"><code class="lang-powershell">$env:DokanLibrary1 = 'C:\Program Files\Dokan\Dokan Library-1.4.0\'
<strong>$env:DokanLibrary1_LibraryPath_x64 = 'C:\Program Files\Dokan\Dokan Library-1.4.0\lib\'
</strong>$env:DokanLibrary1_LibraryPath_x86 = 'C:\Program Files\Dokan\Dokan Library-1.4.0\x86\lib\'
$env:DokanLibrary2 = 'C:\Program Files\Dokan\DokanLibrary-2.0.6\er'
</code></pre>
{% endtab %}

{% tab title="Command Prompt" %}
```
setx /m DokanLibrary1 "C:\Program Files\Dokan\Dokan Library-1.4.0\"
setx /m DokanLibrary1_LibraryPath_x64 "C:\Program Files\Dokan\Dokan Library-1.4.0\lib\"
setx /m DokanLibrary1_LibraryPath_x86 "C:\Program Files\Dokan\Dokan Library-1.4.0\x86\lib\"
setx /m DokanLibrary2 "C:\Program Files\Dokan\DokanLibrary-2.0.6\"
```
{% endtab %}
{% endtabs %}





### <mark style="color:blue;">GPG SHORTCUTS</mark>

{% tabs %}
{% tab title="Keys" %}
The following can be used to set your GPG key IDs to an environment variable so that you don't have to keep typing the gpg commands.



Change <mark style="color:red;">**`ABCDEF1234560`**</mark> and <mark style="color:red;">**`ABCDEF1234561`**</mark> to your own key IDs. You can get your key IDs by using the command <mark style="color:red;">**`gpg --list-secret-keys --keyid-format=long`**</mark>

```
setx /m KEY_ID1 "ABCDEF1234560"
setx /m KEY_ID2 "ABCDEF1234561"
```



Once you have applied these new variables, you can open <mark style="color:red;">**`Command Prompt`**</mark> and type:

```
%KEY_ID1%
%KEY_ID2%
```

\
To call these variables in <mark style="color:yellow;">**`Powershell`**</mark>, you need to call them a bit differently:

```powershell
iex $env:KEY_ID1
iex $env:KEY_ID2
```
{% endtab %}

{% tab title="Shortcuts" %}
The list below contains shortcuts you can use so that you don't have to remember certain commands:



```
setx /m gpglong "gpg --list-secret-keys --keyid-format=long"
setx /m gpgshort "gpg --list-secret-keys --keyid-format=short"
```

\
Once you have applied these new variables, you can open <mark style="color:red;">**`Command Prompt`**</mark> and type:

```
%gpglong%
%gpgshort%
```

\
To call these variables in <mark style="color:yellow;">**`Powershell`**</mark>, you need to call them a bit differently:

```powershell
iex $env:gpglong
iex $env:gpgshort
```
{% endtab %}
{% endtabs %}



You can use your <mark style="color:red;">**`KEY_ID`**</mark> variables in commands by executing:

{% tabs %}
{% tab title="Command Prompt" %}
<pre><code><strong>gpg --expert --edit-key %KEY_ID1%
</strong></code></pre>
{% endtab %}

{% tab title="Powershell" %}
```
gpg --expert --edit-key $env:KEY_ID1
```
{% endtab %}
{% endtabs %}



## <mark style="color:red;">❊ Command Prompt -> Set ENV -> Append</mark>

This is a list of commonly needed environment variables for this guide. Make sure you check the paths to ensure that yours are the same.

The following command can be used to append to your existing <mark style="color:red;">**`PATH`**</mark>.





The commands below will APPEND whatever is currently set for PATH and add the new path to the end of the line. Check the paths on these before you add them as your paths may be different:

{% tabs %}
{% tab title="Powershell" %}
```powershell
$env:Path += ';C:\Program Files\Yubico\YubiKey Manager CLI\'
$env:Path += ';C:\Program Files\Git\bin'
$env:Path += ';C:\Program Files\Yubico\Yubico PIV Tool\bin'
$env:Path += ';C:\Program Files (x86)\Gpg4win\bin'
$env:Path += ';C:\Program Files\Yubico\Yubico Challenge Response\bin'
$env:Path += ';C:\Program Files\OpenSSL-Win64\bin'
$env:Path += ';C:\Program Files\PuTTY\'
$env:Path += ';C:\Program Files\Yubico\YubiKey Manager'
$env:Path += ';E:\Libraries\Git\cmdn'
$env:Path += ';I:\SoftHSM2\lib'
$env:Path += ';F:\OpenSSH-Win6'
```
{% endtab %}

{% tab title="Command Prompt" %}
```
setx /M PATH "%PATH%;C:\Program Files\Yubico\YubiKey Manager CLI\"
setx /M PATH "%PATH%;C:\Program Files\Git\bin"
setx /M PATH "%PATH%;C:\Program Files\Yubico\Yubico PIV Tool\bin"
setx /M PATH "%PATH%;C:\Program Files (x86)\Gpg4win\bin"
setx /M PATH "%PATH%;C:\Program Files\Yubico\Yubico Challenge Response\bin"
setx /M PATH "%PATH%;C:\Program Files\OpenSSL-Win64\bin"
setx /M PATH "%PATH%;C:\Program Files\PuTTY\"
setx /M PATH "%PATH%;C:\Program Files\Yubico\YubiKey Manager"
setx /M PATH "%PATH%;E:\Libraries\Git\cmdn"
setx /M PATH "%PATH%;I:\SoftHSM2\lib"
setx /M PATH "%PATH%;F:\OpenSSH-Win64"
```
{% endtab %}
{% endtabs %}





