{"id":86618,"date":"2020-03-03T15:44:59","date_gmt":"2020-03-03T15:44:59","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=86618"},"modified":"2021-04-29T15:25:06","modified_gmt":"2021-04-29T15:25:06","slug":"how-to-create-an-ubuntu-powershell-development-environment-part-2","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/database-administration-sql-server\/how-to-create-an-ubuntu-powershell-development-environment-part-2\/","title":{"rendered":"How to Create an Ubuntu PowerShell Development Environment \u2013 Part 2"},"content":{"rendered":"<p><strong>The series so far:<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/database-devops-sql\/how-to-create-an-ubuntu-powershell-development-environment-part-1\/\">How to Create an Ubuntu PowerShell Development Environment \u2013 Part 1<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/sql-linux\/how-to-create-an-ubuntu-powershell-development-environment-part-2\/\">How to Create an Ubuntu PowerShell Development Environment \u2013 Part 2<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/sql-linux\/how-to-create-an-ubuntu-powershell-development-environment-part-3\/\">How to Create an Ubuntu PowerShell Development Environment \u2013 Part 3<\/a><\/li>\n<\/ol>\n\n<p>Part 1 of this series covered the need for creating a Linux development environment for testing and learning. It demonstrated how to install VirtualBox and generate an Ubuntu 19.10 virtual machine.<\/p>\n<p>In this article, you\u2019ll finish setting up your development environment by installing PowerShell, Visual Studio Code, and other tools into the Ubuntu VM.<\/p>\n<p>This will create a foundation for a future article, in which you\u2019ll see how to install Docker, then SQL Server into your VM. You\u2019ll then see how to use PowerShell to work with SQL Server as it runs in the Docker container.<\/p>\n<h2>Installing PowerShell<\/h2>\n<p>Now you\u2019re finally ready to install PowerShell. There are two methods for doing the install. The first is via the Ubuntu Software store. In Ubuntu, click on the big orange briefcase icon in the left-side toolbar. This will launch the Ubuntu Software store. At the top, next to the Updates button, is the search icon; it looks like a magnifying glass. Click in and enter the word <em>PowerShell<\/em>. You\u2019ll come up with a couple of hits.<\/p>\n<p>The first item, <em>powershell<\/em>, will install the most current version of PowerShell, 6.2.3 as of this writing. The <em>powershell-preview<\/em> item will install the next version of PowerShell, the version still in beta. As of this writing, that will be 7.0.0. There may be other items listed, but they aren\u2019t relevant to this exercise.<\/p>\n<p>Using the software store via the GUI may seem easy, but PowerShell lovers are supposed to be command-line geeks! So, close the software store and return to the terminal. Once there enter the following command.<\/p>\n<pre class=\"lang:none theme:none\">sudo snap install powershell --classic<\/pre>\n<p>The basics of the snap command are straight forward. You will want to <code>install<\/code> a <code>snap<\/code>, and the name of the snap is <code>powershell<\/code>. The last part of the command, <code>--classic<\/code>, is quite important. Most snaps install with restrictions that prevent them from diving into system data or execute system-level tasks. PowerShell, however, is meant to do exactly those things. By adding <code>--classic<\/code> to the end of the snap command, you are permitting PowerShell to have access to system-level data and commands.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86619\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-10.png\" \/><\/p>\n<p>Now that it is installed, you can launch PowerShell in one of two ways. First, you can go to the Ubuntu start menu, find the PowerShell icon, and launch it.<\/p>\n<p>Alternatively, from in the terminal window, you can enter <code>pwsh<\/code> and launch the PowerShell command line.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86620\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-11.png\" \/><\/p>\n<p>From here, you can enter the majority of PowerShell commands you\u2019ve come to know and love. For example, enter <code>Get-ChildItem<\/code> to get a list of the files in the directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86621\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-12.png\" \/><\/p>\n<p>PowerShell also has its built-in <code>$PSVersionTable<\/code> variable. Simply enter <code>$PSVersionTable<\/code> on the command line and press enter to return the version number and other info for your current PowerShell session.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86622\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-13.png\" \/><\/p>\n<p>I would assume you are following along setting up PowerShell on an Ubuntu based distro that supports snaps. However, if you want more info and download links you can go <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/scripting\/install\/installing-powershell-core-on-linux?view=powershell-6\">here<\/a>. This takes you to the most current production version of PowerShell as of this writing, version 6.<\/p>\n<h2>PowerShell Core on Linux vs PowerShell Core on Windows<\/h2>\n<p>I want to take a moment to divert from the instructions to mention a subtle but important difference in running PowerShell Core on Linux versus on Windows. In the Windows install of PowerShell Core, many native Linux commands are aliased.<\/p>\n<p>Say you\u2019ve installed PowerShell Core on Windows. You can open a CMD (command) window and launch PowerShell Core by entering <code>pwsh<\/code>, just like you did on Linux. Once open, if you enter the command <code>ls<\/code>, you get the same information as if you\u2019d entered <code>Get-ChildItem<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"659\" height=\"478\" class=\"wp-image-86623\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-14.png\" \/><\/p>\n<p>This is because the Windows version uses the alias abilities of PowerShell to remap most Linux commands to PowerShell cmdlets. You can see this for yourself using the Get-Alias cmdlet.<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">Get-Alias -Definition Get-ChildItem<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"659\" height=\"478\" class=\"wp-image-86624\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-15.png\" \/><\/p>\n<p>In this output, you see three different commands all map to the <code>Get-ChildItem<\/code> cmdlet, including the <code>ls<\/code> command.<\/p>\n<p>Return to the terminal in the Ubuntu virtual machine. If you enter the command ls, instead of the output of <code>Get-ChildItem<\/code>, you get the standard output from ls you would expect in Linux, not the output from Get-ChildItem. Indeed, if you run the same <code>Get-Alias -Definition Get-ChildItem<\/code> cmdlet, you\u2019ll see it is missing the mapping from ls that Windows has.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86625\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-16.png\" \/><\/p>\n<p>It&#8217;s important to understand and remember when you enter Linux native commands in PowerShell Core running on Windows; they are remapped to PowerShell Core cmdlets. However, when running native Linux commands in PowerShell Core on Linux, the commands are passed through to the operating system.<\/p>\n<h2>Installing VSCode<\/h2>\n<p>You now have the ability to run PowerShell. Next you want to have a good editor for developing and debugging your PowerShell scripts. While you could use even a simple editor like the previously installed VIM, the editor of choice is VSCode, also referred to as Visual Studio Code. While VSCode is available in the Ubuntu Software store, it is even easier to install via a snap.<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">sudo snap install --classic code<\/pre>\n<p>Note, you may find older articles on the web stating you should install using <em>vscode<\/em>, not <em>code<\/em>. In the beginning days of VSCode, the snap was done and maintained by people in the community. At some point, Microsoft took over maintenance of the snap, and when they did, renamed it to just <em>code<\/em> to distinguish it from the older community-based snap.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86626\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-17.png\" \/><\/p>\n<p>Here you can see you\u2019ve successfully installed VSCode. You can launch it by either going to the Ubuntu start menu and launching it or simply entering <code>code<\/code> on the command line.<\/p>\n<p>As long as VSCode is open, configure it with a few extensions you\u2019ll need. VSCode gets its flexibility by using <em>extensions<\/em>. Extensions provide a variety of useful features. Most notably the ability to use various languages, including syntax highlighting, compilation, and more. Other extensions extend the capabilities of VSCode by adding new components, such as toolbars, to VSCode.<\/p>\n<p>Over on the left, the lower most icon will open the extensions pane (pointed to by the big arrow), click on it to open the extensions pane.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86627\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-18.png\" \/><\/p>\n<p>In the search pane at the top of the extensions enter <em>powershell<\/em>. When you do a list of PowerShell related extensions. The very top one is the one you need to provide syntax highlighting as well as adding a PowerShell terminal to VSCode. Click on the entry, and to the right, the details for the extension are shown. Just click on the green <em>Install<\/em> button to install the PowerShell extension. Note that you will need to have PowerShell installed already for the extension to work.<\/p>\n<p>After installation, you\u2019ll note the color scheme of VSCode has been updated.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86628\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-19.png\" \/><\/p>\n<p>The PowerShell extension updates the colors of VSCode to look like the original PowerShell ISE from Windows. If you only use PowerShell and like the original color scheme, then you can leave it alone. I prefer the dark scheme, so if you do as well click on the <em>Dark+ (default dark)<\/em> option to return to the original color scheme.<\/p>\n<p>There are a few more extensions you\u2019ll want if you\u2019ll be working with tools like SQL Server (which the next article covers), or bash scripts. In addition, many projects are including documentation right within their VSCode projects using <em>markdown<\/em>. Markdown provides a simple syntax for formatting your documents. It\u2019s much simpler than using HTML but being entirely text-based is not quite as simple as Microsoft Word.<\/p>\n<p>Return to the extension search box, then search for and install the following extensions:<\/p>\n<ul>\n<li>SQL Server (mssql)<\/li>\n<li>Bash Debug<\/li>\n<li>Markdown All in One<\/li>\n<li>Markdown Preview Enhanced<\/li>\n<\/ul>\n<p>Note there are several versions of Markdown Preview Enhanced, you\u2019ll want the one from developer Yiyi Wang.<\/p>\n<p>You can confirm everything installed by clicking on the \u2026 menu to the right of the word Extensions at the top of the pane. It brings up a menu, from it, select <em>Show Installed Extensions<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86629\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-20.png\" \/><\/p>\n<p>Here you can see the base set of extensions you\u2019ll want for a PowerShell \/ SQL Server development box.<\/p>\n<p>There is one last \u201ctweak\u201d I like to make to my VSCode installations. This is an optional step, and you may wish to alter it based on your preferences. I like to use a tab size of two characters, and always insert spaces instead of using the tab character. To make these settings the default, In the VSCode menu, select <em>File<\/em>, <em>Preferences<\/em>, then <em>Settings<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"600\" class=\"wp-image-86630\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-21.png\" \/><\/p>\n<p>The settings will now appear in a new tab. While you could hunt through the huge list of settings and update them via the GUI, it is much faster to edit the json settings file directly. To do so, click on the <em>Open Settings (JSON)<\/em> icon in the upper right (pointed to by the big arrow).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86631\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-22.png\" \/><\/p>\n<p>If this is a fresh install, your settings file should just be a pair of curly braces. Insert these lines between them:<\/p>\n<pre class=\"lang:none theme:none \">\/\/ The number of spaces a tab is equal to\r\n\"editor.tabSize\": 2,\r\n\/\/ Insert spaces when pressing tab\r\n\"editor.insertSpaces\": true,\r\n\/\/ When opening a file, tabsize and insert spaces will be detected \r\n\/\/based on the file type\r\n\"editor.detectIndentation\": true<\/pre>\n<p>When you do, your settings file should resemble the following:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86632\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-23.png\" \/><\/p>\n<p>Be sure to save this using the <em>File, Save<\/em> menu or using <em>Ctrl+S<\/em>. If you had other settings in the file, be sure it follows proper json syntax, and that there is a comma between each setting, excluding a comma at the end of each line.<\/p>\n<p>From here, your new files will be saved with these settings. If you have an existing file you want to change over, you can use Ctrl+Shift+P to open up the command pallet then use the following command to update the file:<\/p>\n<pre class=\"lang:none theme:none\">Convert Indentation to Spaces<\/pre>\n<p>I want to emphasize these last few steps of updating the settings file is entirely optional. You may prefer tabs, or you may wish to set your tab size to 3, for example. This is a personal preference of mine, and I\u2019ve included it so you can see how to update your settings file to suit your personal preferences.<\/p>\n<p>This concludes the installation and configuration of VSCode. There\u2019s one last item you will want to install, and you\u2019ll do that in the next section.<\/p>\n<h2>Installing Azure Data Studio<\/h2>\n<p>Azure Data Studio is the open source, a multiplatform tool for interacting with SQL Server, as well as other databases. You can think of this as the new version of SQL Server Management Studio. Like VSCode and PowerShell Core, it will run on Linux, Windows, and macOS.<\/p>\n<p>Unfortunately, Azure Data Studio is not yet available via a snap. You\u2019ll have to combine a manual download with some command line work. Before you install, some pre-requisites need to be installed on Ubuntu based systems. The following command, entered at the terminal, will install the three libraries you need.<\/p>\n<pre class=\"lang:none theme:none\">sudo apt-get -y install libxss1 libgconf-2-4 libunwind8<\/pre>\n<p>For clarity, the first library, <code>libxss1<\/code>, ends in the number <strong>one<\/strong>, not the letter L.<\/p>\n<p>Next, you\u2019ll have to open Firefox (built into Ubuntu by default, although you can pick a different web browser if you want to install one) and go <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/azure-data-studio\/download?view=sql-server-2017\">here<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86633\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-24.png\" \/><\/p>\n<p>Scroll down just a little and find the <em>.deb<\/em> link. Click on the link, pick <em>Save file<\/em>, and save to your downloads directory. (Note, don\u2019t use the default of <em>Open with Software Install<\/em>, you\u2019ll need to do some extra things after downloading that the default software installer doesn\u2019t handle).<\/p>\n<p>Once the download is complete, return to the terminal and get a listing of the downloaded file by entering the following command:<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">ls .\/Downloads<\/pre>\n<p>A reminder, case is very important. The D in Downloads must be capitalized; there is no folder called downloads.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86634\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-25.png\" \/><\/p>\n<p>Here you can see you have one file, the .deb file you just downloaded. You can now extract the contents with the following command.<\/p>\n<pre class=\"lang:none theme:none\">sudo dpkg -i .\/Downloads\/azuredatastudio-linux-1.14.0.deb<\/pre>\n<p>Note, Azure Data Studio is being updated on a fast and regular basis, so the version number (here, 1.14.0) may not match the version you get. That\u2019s OK, it\u2019s why you list out the files in the download folder. Just replace the file name with the one you downloaded.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86635\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-26.png\" \/><\/p>\n<p>To launch it the first time, type in <code>azuredatastudio<\/code> and hit enter. Alternatively, you can go to the Ubuntu start menu and launch it from the list of applications there.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86636\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-27.png\" \/><\/p>\n<p>Here you can see Azure Data Studio is running and is prompting to connect to a database. For now, just hit the <em>cancel<\/em> button the exit Azure Data Studio.<\/p>\n<h2>Configuring Ubuntu Favorites<\/h2>\n<p>By default, the favorites toolbar on the left side of Ubuntu is configured for the average desktop user. Most developers like to have their development tools in the favorites for quick and easy access. Sure, you could right-click on each one in the favorites bar, pick the remove from favorites option. Then you would open up the start menu, and for each application you want, right-click and choose the add to favorites menu item. But there\u2019s a much faster, quicker way to go about this.<\/p>\n<p>To customize it, you first have to understand where the favorites are stored. Open up a terminal, and enter the following command:<\/p>\n<pre class=\"lang:none theme:none\">\/usr\/bin\/gsettings get org.gnome.shell favorite-apps<\/pre>\n<p>The command returns to you an array of applications, listed in the order they appear in the favorites bar.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86637\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-28.png\" \/><\/p>\n<p>To get the list of my favorites, I did a one time remove and add of my apps manually. This way I\u2019d be assured of getting my list in the order I wanted. Once that was done, I used the <code>gsettings get<\/code> command again, to get my personalized list.<\/p>\n<p>Here is the command for my list, yours of course may vary based on your preferences. Enter all of this in a single command.<\/p>\n<pre class=\"lang:none theme:none\">gsettings set org.gnome.shell favorite-apps \"['firefox.desktop', 'org.gnome.Terminal.desktop', 'org.gnome.Nautilus.desktop', 'code_code.desktop', 'azuredatastudio.desktop', 'org.gnome.Software.desktop', 'yelp.desktop']\"<\/pre>\n<p>A side note, the <code>yelp<\/code> does not refer to the restaurant review website; it\u2019s the Ubuntu help system. After updating, my new set of favorites appear.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"802\" height=\"674\" class=\"wp-image-86638\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2020\/03\/word-image-29.png\" \/><\/p>\n<p>Here you can see my favorites bar has been updated, with the icons that I will use most of the time in a development world. Having this as a single command means I can quickly setup and configure new virtual machines as I need them.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article you continued your work from part 1. You installed PowerShell Core, then installed and configured Visual Studio Code. You added on the installation of Azure Data Studio to prepare for future database work.<\/p>\n<p>The article wrapped up by automating the update to the favorites bar, configuring it for a development centric environment. This will make it easier to set up new development VMs in the future.<\/p>\n<p>This puts you in a good position for growth. Future articles will expand on this base, including one on installing SQL Server in a Docker container on Linux.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You\u2019ll need several tools in place to effectively work with SQL Server in Linux. In this article, Robert Cain explains how to install these tools in your Ubuntu virtual machine. &hellip;<\/p>\n","protected":false},"author":316962,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143527,53],"tags":[95505],"coauthors":[52865],"class_list":["post-86618","post","type-post","status-publish","format-standard","hentry","category-database-administration-sql-server","category-featured","tag-compliant-database-devops"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/86618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/316962"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=86618"}],"version-history":[{"count":4,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/86618\/revisions"}],"predecessor-version":[{"id":86646,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/86618\/revisions\/86646"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=86618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=86618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=86618"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=86618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}