CLI not added to Powershell path on Windows

I recently tried installing the exercism CLI on windows 11 using the installer. I went with the default install location which was C:\Exercism. When I then tried to run the configuration step in Powershell I got an error saying the “The term ‘exercism’ is not recognized…”. I checked the path with $env:Path and it seems the default install location is not there.

You can add the location to your path temporarily with:

$env:Path += ";C:\Exercism"

and can make the change permanent by adding it to your powershell profile. I didn’t have one before so I did:

New-Item -Path $profile -ItemType "file" -Force
notepad $profile

and then pasted:

$env:Path += ";C:\Exercism"

into it.

I just wanted to flag this in case anyone else ran in to the problem. I haven’t done any windows programming before so hopefully this was an ok way to do it. From what I understand Powershell is a more modern shell than command prompt so it might be worth adding this to the instructions to encourage best practice.

Welcome to the forum!

The installer does update your path: windows-installer/Delphi/Project/Source/uUpdatePath.pas at 3bcbd8f2b1bdbbfc36c078697c222fffe77f188d · exercism/windows-installer · GitHub

What I guess happened is that you had a Powershell opened before you started the installation, and after the installation you tried to run the command in that Powershell that was already opened. For environment variables to refresh, you’d need to start a new Powershell after the installation.

Check you $env:Path again - my guess is that C:\Exercism is now duplicated there after you appended to your profile too.

An alternative to adding the variable to your profile would be to add it to your user in the Windows settings, search for “Edit the system environment variables” on windows and you should see the menu that let’s you edit the env vars for your user and your system, including PATH. I find it’s easier to edit and see the env vars here.

If you want to do the same using Powershell, start a Powershell in Administrator mode and run:

[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Exercism", "User")

Doing this will set the env var for your user, which can then be visible by any shell, not just Powershell. But again, I don’t think messing with env vars manually was needed here.

Yes. Powershell is more powerful overall and can do things that the command prompt can’t. There are also different versions of Powershell. Most windows installations by default ship with Powershell 5, but there is also Powershell 7 which fixes many issues with Powershell 5 and adds even more functionality.

I don’t think manually messing with the env vars was needed here. The installer should set if for you, and you probably just needed a Powershell restart.

Note that restarting the shell to see updates to env vars is often needed in most shells, not just Powershell. Maybe including a note the restart the shell you are currently using could be added to the instructions.

There’s no need to recommend any particular shell as “best practice” in the installation instructions - every user should choose the one they want to use and the exercism command should work in all of them, since it updates the PATH and all shells I know read from PATH to look for executables.

1 Like

You were right! It’s strange, I swear I tried closing and reopening Powershell before I posted here, maybe I closed the wrong tab or something.

Yes I was mistaken before.

“Best practice” was perhaps a poor choice of words. I was referring here to the manual installation instructions for windows which I looked at briefly after I ran into issues. In those instructions it says to use command prompt to run exercism. I’m sure the CLI will run equally well either way, but in my (admittedly not particularly well informed) opinion it makes more sense to introduce people to the more modern tools when you can.

Say for example this was someone’s first time using the command line and they decided to learn more about it. After reading these instructions the first thing they’d google might be something like “command prompt tutorial”. I think that would be a shame because there is a more modern alternative sitting right there that they might not realise for some time.

In any case, thanks for the tips about environment variables!

Can you point me to those instructions? I looked at the CLI Walkthrough and the Working Locally instructions and I can’t seem to find references to the command prompt.

You’re welcome!

If you go to the CLI Walkthrough then click:
Windows → Proceed with manual installation → Yes
You will find the command prompt instructions.

I see. I think it’s fine for these instructions to show the command prompt, since they are giving you a step-by-step introduction.

But maybe in the introduction before the steps, it could briefly mention that you only need a terminal and any shell will work, but for demonstration, the command prompt will be used. I don’t think it should go into much detail about the alternatives. If you are new to the command line, being presented with alternatives you must consider can be overwhelming.

I’m not sure there was a reason not to use something else, e.g Powershell not being available in all windows installations (although I think it is?). Still, in the end, I don’t think it matters too much because to get exercism running, the command prompt will do just fine.