A great way to get started using OpenShift on Windows is by using the CLI (Command Line Interface) with the OpenShift Origin Client Tools (OC Tools). This can be downloaded as a zip for Windows, and provides some powerful commands and an alternative to the web console for working with OpenShift locally or remotely. You may not think that you need this, but give it a try, and you’ll probably be glad that you did.
I wrote these instructions using Windows 8.1 Pro, but the process should be the same or similar on Windows 10 and earlier versions such as Windows Vista, Windows 7, and Windows XP.
Download OC Tools
First, head to this page and look for the current Windows client tools release under “Downloads”: https://github.com/openshift/origin/releases
After downloading the zip, go ahead and open it, and Extract all. We’re going to create
C:Program Files (x86)OpenShift and place it there.
Once this is done, check out the README.md where you can learn about the origin of OpenShift and how it works. This is a great place to get started with putting your projects on OpenShift.
Setting the PATH
Next, it’s time to set the system PATH environment variable for the directory containing oc.exe, which now resides in your newly created OpenShift folder. This makes it easy to access OC Tools by simply opening up command prompt and typing in an
oc command. (Tip: In some versions of Windows, you can quickly open the command prompt by pressing Windows + X.)
Way 1: Using the System Control Panel (Recommended)
Open the Control Panel (hit the Windows key and then type
Control Panel on 8.1 and above), and click on System. Click on Advanced system settings on the left or open the Advanced tab of System Properties. Click the button labeled Environment Variables… at the bottom. Look for the option in the User variables section for Path.
This will bring up a window that has a Variable value: form. Inside of this are each of the directories in the PATH, separated by a semicolon (;). Go to the end of this and add
;C:Program Files (x86)OpenShift. Click OK to save it.
Way 2: Using setx in the Command Prompt (Not Recommended)
Alternatively, you can add the directory to PATH through the command prompt. WARNING: Be careful doing it this way, as it will truncate the variables in your PATH to 1024 characters. If you have many paths in here, some will get lost (including the one that you just added), and there is no way around this, meaning that you cannot add anything this way.
You can see what is on your PATH by simply typing
path in the command prompt. (This would be good to check if you’re unsure if your PATH variables go beyond 1024 characters.) If your PATH is relatively short, then you can add to it in the terminal by typing
setx PATH=%PATH%;C:Program Files (x86)OpenShift. This will permanently append it to your PATH environment variable (meaning that it will still be there after you exit the terminal).
Way 3: Editing the Registry
If neither of the above options are satisfactory to you, then try editing the registry directly. Warning: Use caution with this method, because things can go wrong easily when editing the registry.
Go to your start menu and type Run. Enter
regedit in the form that pops up. This will open a branching directory to navigate. Go to HKEY_LOCAL_MACHINE -> System -> CurrentControlSet -> Control -> Session Manager -> Environment, then find Path and right-click on it and select Modify…. Append
;C:Program Files (x86)OpenShift and restart for this to take effect.
Way 4: PowerShell
Caution: This method also seems to have a character limit, so it may not work if you already have a lot of variables in PATH.
After you start up PowerShell, enter the following:
$PATH = [Environment]::GetEnvironmentVariable("PATH")` $oc_path = "C:Program Files (x86)OpenShift"` [Environment]::SetEnvironmentVariable("PATH", "$PATH;$oc_path")`
A restart may be required after this to see the new variable in PATH take effect.
Way 5: The Lazy Way (Not Recommended)
Alternatively, you can copy & paste oc.exe into
C:Windows or any other directory already on your PATH. This isn’t recommended because it separates the .exe from the directory with the README, LICENSE, and version number, but is a quick way to get the job done if you don’t want to set the PATH. (Don’t do this; adding to your PATH isn’t that hard once you know how.)
Test Out OC Tools
Now, test it out by opening up command prompt and entering
oc version. You should now see the version number that you just downloaded.
Once you have this installed, check out my series on deploying your ASP.NET apps on OpenShift. Also head to the documentation to check out what you can now do with OC Tools.
What tips for using OpenShift on Windows would you like to see next? Leave a comment to let us know!
Red Hat Enterprise Linux is available in Cloud Server Red Hat