wsl Archives - ProdSens.live https://prodsens.live/tag/wsl/ News for Project Managers - PMI Sun, 24 Mar 2024 02:20:48 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://prodsens.live/wp-content/uploads/2022/09/prod.png wsl Archives - ProdSens.live https://prodsens.live/tag/wsl/ 32 32 Warp terminal on WSL is AMAZING https://prodsens.live/2024/03/24/warp-terminal-on-wsl-is-amazing/?utm_source=rss&utm_medium=rss&utm_campaign=warp-terminal-on-wsl-is-amazing https://prodsens.live/2024/03/24/warp-terminal-on-wsl-is-amazing/#respond Sun, 24 Mar 2024 02:20:48 +0000 https://prodsens.live/2024/03/24/warp-terminal-on-wsl-is-amazing/ warp-terminal-on-wsl-is-amazing

If you’re a developer working with Windows Subsystem for Linux (WSL), prepare to be amazed by Warp Terminal.…

The post Warp terminal on WSL is AMAZING appeared first on ProdSens.live.

]]>
warp-terminal-on-wsl-is-amazing

If you’re a developer working with Windows Subsystem for Linux (WSL), prepare to be amazed by Warp Terminal. My journey with Warp began by following the footsteps of @ljtruong, updating Ubuntu, and ensuring all packages were up to date. The real magic started when I downloaded and installed the Warp Terminal.

Installation: A Breeze
The process was straightforward. I grabbed the .deb file directly from Warp’s official download page and installed it within WSL using the following command:

sudo dpkg -i warp-terminal_.deb

Execution: Smooth and Seamless
Running Warp Terminal was as simple as setting a couple of environment variables. I added these lines to my ~/.bash_profile:

export WARP_ENABLE_WAYLAND=1
export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
export BROWSER=google-chrome

With these variables set, launching Warp Terminal was just a matter of typing warp-terminal into the console.

Authentication: Secured and Swift
To obtain the authentication token, I installed Google Chrome in WSL. Downloading and installing Chrome was a quick two-step process:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt -y install ./google-chrome-stable_current_amd64.deb

After setting Chrome as the default browser and adding export BROWSER=google-chrome to my profile config, I logged into Warp’s remote login page. A few clicks later, Warp Terminal synced with the authentication token, and I was ready to go.

The Result: Beyond Expectations
The result was nothing short of spectacular. Warp Terminal on WSL is not just another terminal; it’s a testament to how seamless development on Windows can be. It’s fast, it’s efficient, and it integrates flawlessly with the graphical environment, thanks to the Wayland support.

For developers looking to streamline their workflow, Warp Terminal is a must-try. It’s not just a tool; it’s an experience that elevates your coding sessions to new heights.

Feel free to adjust the content to better fit your voice and experience. Happy blogging!

The post Warp terminal on WSL is AMAZING appeared first on ProdSens.live.

]]>
https://prodsens.live/2024/03/24/warp-terminal-on-wsl-is-amazing/feed/ 0
How to Connect WSL2 (with Laravel App) to a XAMPP MySql Server on Windows https://prodsens.live/2022/10/23/how-to-connect-wsl2-with-laravel-app-to-a-xampp-mysql-server-on-windows/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-connect-wsl2-with-laravel-app-to-a-xampp-mysql-server-on-windows https://prodsens.live/2022/10/23/how-to-connect-wsl2-with-laravel-app-to-a-xampp-mysql-server-on-windows/#respond Sun, 23 Oct 2022 00:21:11 +0000 https://prodsens.live/2022/10/23/how-to-connect-wsl2-with-laravel-app-to-a-xampp-mysql-server-on-windows/ how-to-connect-wsl2-(with-laravel-app)-to-a-xampp-mysql-server-on-windows

You have a MySql server running on Windows perhaps with XAMPP. You also have Wsl2 and want to…

The post How to Connect WSL2 (with Laravel App) to a XAMPP MySql Server on Windows appeared first on ProdSens.live.

]]>
how-to-connect-wsl2-(with-laravel-app)-to-a-xampp-mysql-server-on-windows

You have a MySql server running on Windows perhaps with XAMPP. You also have Wsl2 and want to access that database from Wsl2 for your for your application. What do you do?

I assume you have XAMPP running already and have Apache and MySql started and you’ve also created a table you want to access. Good.

You also have a Laravel app and you are having problem running:

$ php artisan migrate

and you are getting such error as:

$ IlluminateDatabaseQueryException

  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = laravel_survey and table_name = migrations and table_type = 'BASE TABLE')

This means that, when you connect from a remote system (and WSL2 is remote system), that you’ll need to create a user with access from Wsl2 and allow connections from Wsl2. You can get more detailed info from this reddit post.

Next you have to check if you have a Sql client on your Wsl2 machine. This client is different from a Sql Server. The client is what you would use to connect to the Sql server on windows.

Try any of the command below. The second command worked for me and I’m on an Ubuntu box. source

$ sudo apt install mysql-client-core-8.0     # version 8.0.27-0ubuntu0.20.04.1, or
$ sudo apt install mariadb-client-core-10.3  # version 1:10.3.31-0ubuntu0.20.04.1

_make sure you’ve also installed a Sql driver if you are running on a Laravel app. Run:
$ sudo apt-get install php7.4-mysql
_

Next, go into PhpMyAdmin, locate your created table and click on it. Navigate to Privileges among the menu at the top of the screen. Find all username with root and click on Edit privileges. Tick on Global privileges and click Go.

Now, there is an alternative method to do this, using Windows Cmd or Shell from XAMPP and connecting to the MySql database directly and type in some SQL code directly.

$ mysql -u root -p -h 127.0.0.1

then type this command in:

> CREATE USER 'root'@'%' IDENTIFIED BY 'root'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

As I’ve written above, what the command does is, create a user with access from Wsl2 and allow connections from Wsl2 or any remote system and as you might tell, could constitute a security risk since you are granting all privileges.

Next, on Wsl2, run:
$ mysql -u root -p -h "$(hostname).local"

Skip the password prompt by tapping enter.

Congratulations, you’ve connected to your MySql database on your Windows host from Wsl2.

Now, for the Laravel app to be able to run migrations, you need to go into the .env file and edit the Sql section but before that, run:
$ echo $(hostname).local

and copy or note the result.

Next, edit the MySql section of your .env file to the following:

DB_CONNECTION=mysql
DB_HOST=DESKTOP-BB111.local #this should be the result of the last command above and should end with .local
DB_PORT=3306
DB_DATABASE=laravel_counter #this is the name of the database you created and as seen on your PhpMyAdmin
DB_USERNAME=root
DB_PASSWORD= #leave this empty

Save that file and get back to your terminal and run:
php artisan migrate

Watch as your migration loads and smile.

You’ve successfully connected your Wsl2 box to a service running on your Windows host. Now if you don’t mind, go reward yourself a bit. Cheers.

Apparently, connecting to a Wsl2 service from windows is much easier and comes set up, I guess because of Port Forwarding.

I hope this post has helped you in some way. Thank you for reading.

The post How to Connect WSL2 (with Laravel App) to a XAMPP MySql Server on Windows appeared first on ProdSens.live.

]]>
https://prodsens.live/2022/10/23/how-to-connect-wsl2-with-laravel-app-to-a-xampp-mysql-server-on-windows/feed/ 0
Set up Node.js on WSL https://prodsens.live/2022/10/10/set-up-node-js-on-wsl/?utm_source=rss&utm_medium=rss&utm_campaign=set-up-node-js-on-wsl https://prodsens.live/2022/10/10/set-up-node-js-on-wsl/#respond Mon, 10 Oct 2022 20:11:25 +0000 https://prodsens.live/2022/10/10/set-up-node-js-on-wsl/ set-up-node.js-on-wsl

Node.js is a JavaScript runtime environment that executes JavaScript code outside a web browser. It allows us to…

The post Set up Node.js on WSL appeared first on ProdSens.live.

]]>
set-up-node.js-on-wsl

Node.js is a JavaScript runtime environment that executes JavaScript code outside a web browser. It allows us to install packages, run local web servers, create APIs, and more.

✅ Requirements

  • Windows 10 or 11
  • WSL or WSL2
  • cURL

🎛 NVM

You will likely need to switch between multiple versions of Node.js based on the needs of the different projects you’re working on. Node Version Manager allows you to quickly install and use different versions of Node via the command-line.

Installing NVM

  • 1. Open your WSL terminal and Install nvm with:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

To verify installation, enter: command -v nvm. This should return nvm, if you receive command not found or no response at all, close your current terminal, reopen it, and try again.

  • 2. List which versions of Node are currently installed (should be none at this point):
nvm ls

Ubuntu terminal displaying node not installed

  • 3. Install both the current and stable LTS versions of Node.js.

Install the current stable LTS release of Node.js (recommended for production applications):

nvm install --lts

Install the current release of Node.js (for testing the latest Node.js features and improvements, but more likely to have issues):

nvm install node
  • 4. List what versions of Node are installed:
nvm ls

Now you should see the two versions that you just installed listed.

Ubuntu terminal displaying node installed

  • 5. Verify that Node.js is installed and the current version:
node --version

Then verify that you have NPM installed as well:

npm --version

Changing Node Versions

Use the following commands to change the version of Node you would like to use for any given project:

Switch to the Current version:

nvm use node

Switch to the LTS version:

nvm use --lts

You can also use the specific number for any additional versions you’ve installed:

nvm use v8.2.1

To list all of the versions of Node.js available, use the command: nvm ls-remote.

📦 NPM

Node Package Manager is the default package manager for Node.js. It is a command-line tool used to download or publish packages and manage the dependencies of a project. There is a searchable repository of all available NPM packages at https://www.npmjs.com/.

New Projects

When creating a new project that will utilize NPM, it must be initialized with the init command. First, make sure you are in the root directory of your project, and then use the following command:

npm init

package.json

npm init generates a package.json file and will prompt you for the metadata of your project. This includes things like the name, version, description, and license. You can think of it as the blueprint of your project as it will also contain the packages it depends on. The metadata can be changed at any time by editing the package.json file after the initialization.

If you would like to automatically populate the initialization with all the default values, you may add the --yes flag.

npm init --yes

Installing Modules

Modules are installed via the npm install or npm i command.

npm install react

The above command will install the React module as a dependency in package.json.

We can also install NPM packages globally on our system. This is useful for utilities like command line interfaces.

Yarn is another widely used node package manager, if we wanted to use it on all our node projects we would need the --global or -g flag.

npm install --global yarn

Dependencies

You can save a module as either a dependency or a developer dependency.

A dependency would be something that your project cannot function properly without.

The --save flag used to be needed to install modules as a dependency, but it is now done automatically with the install command.

npm install --save gray-matter

Is the same as:

npm install gray-matter

VS Code example of the dependencies section of package.json

Developer Dependencies

A developer dependency would be the modules used to build the project, not run it. This would include things like linters and testing tools.

Developer dependencies are added with the --save-dev or -D flag. This adds the module to the devDependencies section of package.json

npm install --save-dev husky

VS Code example of the devDependencies section of package.json

Batch Installing

Apart from installing a single module, you can install all modules that are listed as dependencies and devDependencies:

npm install

This will install all modules listed in the package.json of your current directory.

If we only wanted to install the dependencies needed to run our project, the --production flag is used:

npm install --production

the --production flag will only install the modules from the dependencies section of package.json and ignore the devDependencies. The perk of this is notably reducing the size of the node_modules folder.

Uninstalling

Removing modules works in the same way as installing them. Flags will need to be used for any global or developer dependencies.

Dependencies:

npm uninstall react

Developer Dependencies:

npm uninstall --save-dev husky

Global Installs:

npm uninstall --global yarn

Versioning

Package versions are identified with major, minor, and patch releases. 8.1.1 would be major version 8, minor version 1, and patch version 1.

You can specify an exact version number by using the @ symbol.

npm install react@17.0.1

Two more symbols we can use are ^ and ~.

^ is the latest minor release.
For example, npm install ^8.1.1 specification might install version 8.3.1 if that’s the latest minor version.

~ is the latest patch release.
In the same way as minor releases, npm install ~8.1.1 could install version 8.1.6 if that’s the latest patch version available.

When using the npm install or npm i command, the latest minor version will be used.

package-lock.json

The exact package versions will be documented in a generated package-lock.json file.

The values found inside the dependencies and devDependencies objects of the package.json file include a range of acceptable versions of each package to install.

package-lock.json is generated by the npm install command and contains the exact versions of the dependencies used.

Scripts

package.json also contains a scripts property that can be defined to run command-line tools installed on the current project. This can include things like running tests, formatting your code, and launching a local server.

VS Code example of the scripts section of package.json

NPM scripts are run by using the run command. With the above configuration, you would use the following command to have prettier format your code:

npm run format

The keys in the scripts object are the command names and the values are the actual commands.

Check out the official npm and Node.js docs for more in-depth guides.

References

The post Set up Node.js on WSL appeared first on ProdSens.live.

]]>
https://prodsens.live/2022/10/10/set-up-node-js-on-wsl/feed/ 0