<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aleksander Brymora</title>
    <description>The latest articles on DEV Community by Aleksander Brymora (@ohaleks).</description>
    <link>https://dev.to/ohaleks</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F463214%2F9dcc851c-1632-4961-88ff-0e77c7266aaa.jpeg</url>
      <title>DEV Community: Aleksander Brymora</title>
      <link>https://dev.to/ohaleks</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ohaleks"/>
    <language>en</language>
    <item>
      <title>Set up WSL2, PostgresQL and Phoenix LiveView on Windows</title>
      <dc:creator>Aleksander Brymora</dc:creator>
      <pubDate>Tue, 08 Sep 2020 09:07:34 +0000</pubDate>
      <link>https://dev.to/ohaleks/set-up-wsl2-postgresql-and-phoenix-liveview-on-windows-3ol5</link>
      <guid>https://dev.to/ohaleks/set-up-wsl2-postgresql-and-phoenix-liveview-on-windows-3ol5</guid>
      <description>&lt;p&gt;Recently I’ve been sucked into the world of Elixir and spreading the word of functional programming. So to stay true to that I thought I’d share my process of setting up from ground up Elixir, Postgress and LiveView project, as there is some setup. And by share, I mean I’ll point you to the docs/articles that helped me and write a tldr;&lt;/p&gt;

&lt;h1&gt;
  
  
  WSL
&lt;/h1&gt;

&lt;p&gt;Here are the &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10"&gt;official WSL docs&lt;/a&gt; with lots of information. &lt;/p&gt;

&lt;p&gt;Here is a rundown on how to set it up plus some bonuses. (do check the docs out as this might get outdated at some point). If you already have it, by all means skip this part. &lt;/p&gt;

&lt;p&gt;There is a lot of restarting so buckle up:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If you want WSL2 — update your windows to version ^1903, build 18362. You can check it by running: Windows logo key + R, type winver, select OK&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open up PowerShell, as Administrator, in any directory and paste in these commands one by one:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Restart your computer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now if you chose to go with WSL2, you need to open up PowerShell as Administrator again in any directory and specify that you want to use it:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;wsl &lt;span class="nt"&gt;--set-default-version&lt;/span&gt; 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It might prompt you to install additional software, which can be acquired here&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Restart your computer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get yourself a Linux distribution of your choosing. I went with newest Ubuntu LTS, as it doesn’t really matter on WSL (unless you care about some packages available only on AUR or other, but then I guess you know what you’re doing).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do this by opening Microsoft Store and searching for Ubuntu and getting 20.04 LTS or newer. After it installs open it up and follow the setup process, by typing in your username and a password of your choosing.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;After that you should be good to go to use WSL in the Ubuntu software, but what I like to do is install Windows Terminal from Microsoft Store that can open up multiple shells and subsystems so you can switch to whatever you like. Aaaand it looks nice… &lt;a href="https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab"&gt;Here is the link&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After you install it, won’t default to Ubuntu, which is not too optimal, so lets change that. Click on the arrow on the top bar and then click on settings. It will open up the json file with settings. Here you can change, keybindings, fonts and other fancy things, but what we’re interested in is the “defaultProfile” which we need to set to guid of the Ubuntu. You can get it from sthe profiles &amp;gt; list and looking for an object with “Ubuntu” in it and copying its guid and pasting it in the “defaultProfile”. After that save the changes and reopen the Terminal. It should now default to Ubuntu and if you ever want to open something else up&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We’ve done all the setup, now we just need to update the distro and we’re good to move on to Postgres. Here are the commands to update (pro-tip add them to your .bash-profile as a shortcut so you can quickly update)&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get upgrade &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  PostgreSQL
&lt;/h1&gt;

&lt;p&gt;Now that took me a while to get, but here is the process.&lt;br&gt;
First of all there are two links that made it all work: &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-database"&gt;Windows docs on installing PostgreSQL (and other DBs)&lt;/a&gt; and a super helpful step by step Medium article by &lt;a href="https://medium.com/@harshityadav95?source=follow_footer--------------------------follow_footer-"&gt;Harshit Yadav&lt;/a&gt; on &lt;a href="https://medium.com/@harshityadav95/postgresql-in-windows-subsystem-for-linux-wsl-6dc751ac1ff3"&gt;PostgreSQL In Windows Subsystem for Linux (WSL)&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open up your terminal, make sure you’re in Linux distro, and run this command to install postgres
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;postgresql postgresql-contrib
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;After that finishes up we need to set up the password for postgres by running this command and typing in the password&lt;br&gt;
sudo passwd postgres&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Notice that this is just like setting up a password for any other user, as this is how PostgreSQL chose to set up.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After we set the password we need to start up our database&lt;br&gt;
sudo service postgresql start&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# you can check the status of the db by running:&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;service postgresql status
&lt;span class="c"&gt;# or you can stop it with&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;service postgresql stop
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Now to an actual setup for normal usage, we need to create a user with this command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; postgres createuser &amp;lt;your_username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;And we need to create the database
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; posgres createdb &amp;lt;your_db_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;And now we need to set up a password for that user that we’ve just created and grant him privilages. Note that when we get to psql you MUST finish all commands with a semicolon
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# opens up psql&lt;/span&gt;
&lt;span class="nb"&gt;sudo&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; posgres psql 
&lt;span class="c"&gt;# sets up a password for the user that you created earlier&lt;/span&gt;
alter user &amp;lt;username&amp;gt; with encrypted password &lt;span class="s1"&gt;'your_new_password'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c"&gt;# we need to grant privilages to the user, so we can use the db that we created on step 6&lt;/span&gt;
grant all privileges on database &amp;lt;db_name&amp;gt; to &amp;lt;username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Ctrl + d to quit the shell and we’re set! Now you can use postgres in any project, but since I’m into Phoenix lately here is a next part about getting that sorted.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Installing Elixir and Phoenix LiveView
&lt;/h1&gt;

&lt;p&gt;Please refer to these docs if something doesnt work anymore in my instructions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to install Elixir (part about ubuntu): &lt;a href="https://elixir-lang.org/install.html#gnulinux"&gt;https://elixir-lang.org/install.html#gnulinux&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;How to install Phoenix framework (with LiveView included): &lt;a href="https://hexdocs.pm/phoenix_live_view/installation.html"&gt;https://hexdocs.pm/phoenix_live_view/installation.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;We need download the erlang installer (refer to the docs linked above if you want the newest version)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;dpkg &lt;span class="nt"&gt;-i&lt;/span&gt; erlang-solutions_2.0_all.deb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Refresh Ubuntu’s ‘update queue’ and install erlang and elixir
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update 
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;esl-erlang elixir
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You should have working Elixir now and their ‘mix’ manager, to cofirm that run ‘irc’ and it should open up an elixir shell. Double ctrl+c will get you out of it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To get started with Phoenix LiveView is as simple as running this command in the folder that you want to work on&lt;br&gt;
mix phx.new my_app --live&lt;br&gt;
The ‘ — live’ flag is whats telling mix to set up a LiveView project, not a simple Elixir project.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NOTE that if you want to install javascript related things you do need to have node installed. For that I strongly suggest using nvm, for which instructions can be found here.&lt;/p&gt;

&lt;h1&gt;
  
  
  Aaight, that’s it.
&lt;/h1&gt;

&lt;p&gt;Probably lot’s of extra stuff, but maybe will help some of you set up some things. Go and make something gorgeous!&lt;/p&gt;

&lt;h2&gt;
  
  
  Edit
&lt;/h2&gt;

&lt;p&gt;Sorry for the weird numbering. Code snippets mess everything up and I'm not sure how would I fix the numbering anyway. &lt;/p&gt;

</description>
      <category>wsl</category>
      <category>postgres</category>
      <category>phoenix</category>
      <category>liveview</category>
    </item>
  </channel>
</rss>
