Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safely relocate existing scoop installation directory? #3852

Closed
wuya666 opened this issue Feb 15, 2020 · 8 comments
Closed

Safely relocate existing scoop installation directory? #3852

wuya666 opened this issue Feb 15, 2020 · 8 comments

Comments

@wuya666
Copy link

wuya666 commented Feb 15, 2020

Currently my system drive is running low on space, and as the scoop directory is taking up more than 30G space, I'm thinking of moving it to a new SSD (drive E) that I just added. I wonder if the following steps are safe and enough to accomplish this:

  1. Stop any running apps and services installed by scoop (MySQL, MongoDB, etc.)
  2. copy the C:\Users\xxx\scoop directory to E:\scoop\xxx\local
  3. copy the C:\ProgramData\scoop directory to E:\scoop\global
  4. uninstall scoop with scoop uninstall scoop
  5. set the environment variables with the commands
$env:SCOOP='E:\scoop\xxx\local'
[Environment]::SetEnvironmentVariable('SCOOP', $env:SCOOP, 'User')
$env:SCOOP_GLOBAL='E:\scoop\global'
[Environment]::SetEnvironmentVariable('SCOOP_GLOBAL', $env:SCOOP_GLOBAL, 'Machine')
  1. install scoop
  2. run scoop reset *

I wonder if the above steps will be safe and enough to do a scoop installation directory relocation? Anything else to watch out for? Since currently my whole development environment is managed by scoop including databases and various IDEs, I'd rather not mess any of them up that'd take days to recover the data and settings, etc.

Thanks.

@ACooper81
Copy link

@wuya666
Copy link
Author

wuya666 commented Feb 17, 2020

You should be able to use symbolic links to make this job easier.
https://winaero.com/blog/create-symbolic-link-windows-10-powershell
https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux

Just tried with both symlink and junction, although things like git, gcc, nodejs, go, java and mobaxterm seem to work without issues, there are already two deal breaker problems I have encountered.

The first is that archwsl completely breaks, and about one third of my development works depend on the Archlinux WSL environment. Even after a complete uninstall and reinstallation, the archwsl just won't start.

The second one is that VScode's code formatter and auto-complete functionalities break, not the standard html and javascript formatters nor the third party formatters installed with go and python extension work. Always says "No formatter installed" (Curiously, the Atom code formatters still work)

Not sure if there will be more deal breaker issues waiting to be discovered with this symlinking/junctioning approach, guess I'll have to take the original plan to try reinstall scoop to the new drive and copy everything there (then modify some environment variables and re-register some services I guess).

@qwmnerbvqwmn
Copy link

today i move scoop to another disk successfully. you should do the follow things:
1.move total scoop to new disk. (if use copy, del old scoop folder, or rename it, to make sure old scoop folder is invaild)
2.open 'scoop/shims/scoop.cmd' and 'scoop/shims/scoop.ps1', update scoop folder path as new location.
3.open win10 environment variables panel, update all variable path contains scoop path to new scoop location. Especially be careful for 'Path' variable in both User and System.
4.create new environment variable in System Variable, variable name is "SCOOP", variable value is new scoop location. if "SCOOP" already exists, just update it.(Maybe scoop software only create this env variable when install location is not default "~/scoop" path)
5.open cmd, execute scoop command, it should work with no any error. execute "where scoop" showing scoop command path, make sure it is new scoop location.
6.execute "scoop reset *" command to recreate all scoop app folder's "current JUNCTION". (junction canot be copy,so it lost target after copy)
7.now it is finish. scoop and all scoop app should work fine now.

@luxzg
Copy link

luxzg commented Apr 24, 2023

today i move scoop to another disk successfully. you should do the follow things: 1.move total scoop to new disk. (if use copy, del old scoop folder, or rename it, to make sure old scoop folder is invaild) 2.open 'scoop/shims/scoop.cmd' and 'scoop/shims/scoop.ps1', update scoop folder path as new location. 3.open win10 environment variables panel, update all variable path contains scoop path to new scoop location. Especially be careful for 'Path' variable in both User and System. 4.create new environment variable in System Variable, variable name is "SCOOP", variable value is new scoop location. if "SCOOP" already exists, just update it.(Maybe scoop software only create this env variable when install location is not default "~/scoop" path) 5.open cmd, execute scoop command, it should work with no any error. execute "where scoop" showing scoop command path, make sure it is new scoop location. 6.execute "scoop reset *" command to recreate all scoop app folder's "current JUNCTION". (junction canot be copy,so it lost target after copy) 7.now it is finish. scoop and all scoop app should work fine now.

I have done my moving using this suggested solution, and it works nicely so far.

I'd like to add a few steps/precautions:

  • step 0. close all scoop apps and services before doing any moving, check your tray and services (eg. Chrome, MSI Afterburner, mysql server service and such)
  • do steps 1-7 as written above
  • step 8. adjust your shortcuts if made manually, eg.
    • Taskbar icons/shortcuts
Windows + R
Type : shell:User Pinned\Taskbar
Press "OK" or "Enter"
  • right click all shortcuts from scoop installed apps, Properties, and adjust path to new location
    • note that Chrome / Chromium contain EXE path PLUS a profile path in same shortcut (command line) and you need to point BOTH to correct locations!!
  • do same for any shortcuts like on Desktop etc

There may or may not be some apps that need some manual tweaking, eg I've found:

  • 7zip file scoop\apps\7zip\current\install-context.reg has path inside that will be applied for right-click menu and it will be wrong, needs update to reg, then re-apply reg
  • mysql server will need service uninstall and reinstall like this (adjust .ini path to your new location and adjust your path inside the INI file itself eg. my C:\scoop\apps\mysql\current\my.ini contains the line pointing to persisted data folder which I forgot to change)
link: https://dev.mysql.com/doc/refman/8.0/en/windows-start-service.html
mysqld --remove
mysqld --install MySQL --defaults-file="C:\scoop\apps\mysql\current\my.ini"
  • a lot of apps (Chrome, Notepad++, 7zip, VLC, ZULU Java, ...) that registered as default apps to open certain files/extensions will need manual updating in registry eg.
\Software\Classes\Applications\<app name>\shell\open\command

I ended up re-scanning whole registry with Ctrl+F searching for a string scoop\apps and modifying all paths to new location. This included default file handling as noted above, services as MySQL example ( Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services ) and several more places. I've also used that to fix some paths that pointed to paths like \scoop\apps\<appname>\<version> instead \scoop\apps\<appname>\current, hopefully I did not mess up something ;D

Anyway, messing with registry you need to beware what you're doing, I'm just saying some apps seem to have registry paths, which may or may not get updated on next app update.

Since I've changed few services, I've also done a full PC reboot, and then another scoop update and scoop update "*" and scoop cleanup --all after it was rebooted.

Main apps I care about to stay "intact" (Chrome and Notepad++ with kazillion tabs) still work fine after this procedure.

@viva-la-v
Copy link

One little thing to add up if you don't want to set the SCOOP environment variable like me.

You will need to use this command to update the root path:

scoop config root_path X:\path\to\scoop

For my case it's:

scoop config root_path D:\scoop

Or else you will still get a bunch of old path in the std out when you run scoop reset *.

@myAlterX
Copy link

myAlterX commented Feb 2, 2024

Just an extra problem I faced. I had pwsh installed with scoop so scoop itself wouldn't run giving me a pwsh not found because its shim was not updated. I opened the scoop shim (D:\scoop\shims\scoop in my case) in notepad and after updating the paths had this:

#!/bin/sh
# D:\scoop\apps\scoop\current\bin\scoop.ps1
if command -v pwsh.exe > /dev/null 2>&1; then
    pwsh.exe -noprofile -ex unrestricted -file "D:\scoop\apps\scoop\current\bin\scoop.ps1"  "$@"
else
    powershell.exe -noprofile -ex unrestricted -file "D:\scoop\apps\scoop\current\bin\scoop.ps1"  "$@"
fi

Because pwsh was installed the first line ran but was giving me a PWSH error (looking in the wrong place) so I just copied the else line into a command line and reset the tool with:

powershell.exe -noprofile -ex unrestricted -file "D:\scoop\apps\scoop\current\bin\scoop.ps1" reset

after which, scoop itself was fixed and so was everything else.

@k2s
Copy link

k2s commented Mar 1, 2024

#3852 (comment) worked for me and I used following script to update the environment variables (execute only if you understand what it does)

# CHANGE THIS
$originalValue = 'c:\users\me\scoop'
$newValue = 'd:\me\scoop'

# Get the current user environment variables
$userEnv = [System.Environment]::GetEnvironmentVariables('User')

# Get the system environment variables
$systemEnv = [System.Environment]::GetEnvironmentVariables('Machine')

# Update the user environment variables
$userKeys = $userEnv.Keys | ForEach-Object { $_ }
foreach ($key in $userKeys) {
    $value = $userEnv[$key]
    if ($value -is [string]) {
        $updatedValue = $value -replace [regex]::Escape($originalValue), $newValue
        if ($updatedValue -ne $value) {
            [System.Environment]::SetEnvironmentVariable($key, $updatedValue, 'User')
            Write-Output "Updated user variable: $key"
        }
    }
}

# Update the system environment variables
$systemKeys = $systemEnv.Keys | ForEach-Object { $_ }
foreach ($key in $systemKeys) {
    $value = $systemEnv[$key]
    if ($value -is [string]) {
        $updatedValue = $value -replace [regex]::Escape($originalValue), $newValue
        if ($updatedValue -ne $value) {
            [System.Environment]::SetEnvironmentVariable($key, $updatedValue, 'Machine')
            Write-Output "Updated system variable: $key"
        }
    }
}

@murphytalk
Copy link

murphytalk commented Mar 18, 2024

Before run the scoop installer script, create a symlink to point to where you want scoop to be installed to : mklink /D c:\Users\MyUserName\scoop D:\Apps\scoop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants