Create environment variables and paths in windows

Environment variable and path setup for windows 10 - Shellscribe

Windows environment variables and paths are essential components of the operating system, acting as pointers to various system locations and resources. They play a crucial role in how applications and the system itself function, helping them locate necessary files, executables, and libraries.

In this article, we'll take a closer look at what environment variables and paths are, why they are important, and how to set them up to customize your computing environment. This guide will provide you with the knowledge and tools to manage them effectively.

Create test file

Before getting started with the environment variables configuration, first we need to create a test file. Then We'll proceed further to call this file using the environment variable. Open powershell and run the below command in it:

>
Set-Content -Path "test_file.bat" -Value "@echo It worked !!"

Above command will create a new file test_file.bat, in the current working directory, that will print "It worked !!" in the powershell upon execution. To test it, open the file in powershell as below:

>
./test_file.bat
executing test file in PowerShell

Now to call this test_file.bat file, you have to change your current directory path to the location where this file is located. In the next section, we'll set up an environment variable and path that will allow us to call this test_file.bat file from anywhere without moving to Its working directory. It'll be just like another command in powershell.

Set up environment variable and path

To call the test file using the environment variable, follow the below process:
  • Press Window key + r to open the run dialog.
  • Type sysdm.cpl and press enter. System properties tab will open.
  • Select Advanced from the top options and open Environment variables. opening environment variables dialog box
  • Select Path under User variables and click on Edit.. button. It will set up variables for the current user. If you want to set up a variable for the whole system, then select System variables. editing path
  • In Edit environment variables box, select New to add a new path. Input the absolute path of the folder where our test file is located. Press OK when finished. adding new path
  • Back in Environment variables box, select New... to add a new variable. New user variable box will open. adding new variable
  • Set Variable name appropriately. It'll be used to call our test file. Then set Variable value to the absolute path of our test file. You can paste the link directly or select the file using Browse file... button. Select OK when finished. adding new variable
  • You can see that the new variable has been added to the User variables list. Select OK to complete the process and close all windows. verifying variable

Testing variable

Open powershell and move to any location other than where the file is located. For example: our test file is located at "C:\Users\protocolten", so we'll move to "C:\" using cd \ command. Now try to use the newly created variable as below:

>
test_file
using variable

Above image verifies that our variable is working as expected. You can use this variable anywhere in the PowerShell or cmd to call the test_file.bat file without defining Its absolute path. Keep in mind that we created a User variable and It can only be used by the current user.

Set up environment variables

Author: Harpreet Singh
Cloud Solution Architect

Created: Thu 14 Mar 2024

⏳ 4 min read

👁️ 519 Views

POST CATEGORY
  1. Windows
  2. Technology
  3. Knowledge
Suggested Posts:
LINUX post image
How to setup on-premise MySQL master and slave servers

In this article I'll be demonstrating how you can configure MySQL master and slave …

NETWORKING post image
CTF Challenges and Solutions from picoGYM by picoCTF

picoCTF is an open-source project. It's an enhanced platform for education and organizing competitions …

WINDOWS post image
Reset windows 10 password using bootable usb drive

Windows 10 by Microsoft is the most used operating system nowadays. Despite being heavily …

LINUX post image
How to deploy Django application with Nginx, MySQL, and Gunicorn on Ubuntu

Django is an open-source web framework based on Python. It can be very efficient …

LINUX post image
Install LAMP on Ubuntu or CentOS with firewall configuration

This tutorial will be focused on installing the LAMP stack (Linux Apache MySQL PHP) …

Sign up or Login to post a comment.

Sign up Login

Comments (0)